Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. public class RealGun_Slide : VRTK_InteractableObject
  5. {
  6. private float restPosition;
  7. private float fireTimer = 0f;
  8. private float fireDistance = 0.05f;
  9. private float boltSpeed = 0.01f;
  10. public void Fire()
  11. {
  12. fireTimer = fireDistance;
  13. }
  14. protected override void Awake()
  15. {
  16. base.Awake();
  17. restPosition = transform.localPosition.z;
  18. }
  19. protected override void Update()
  20. {
  21. base.Update();
  22. if (transform.localPosition.z >= restPosition)
  23. {
  24. transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, restPosition);
  25. }
  26. if (fireTimer == 0 && transform.localPosition.z < restPosition && !IsGrabbed())
  27. {
  28. transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z + boltSpeed);
  29. }
  30. if (fireTimer > 0)
  31. {
  32. transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z - boltSpeed);
  33. fireTimer -= boltSpeed;
  34. }
  35. if (fireTimer < 0)
  36. {
  37. fireTimer = 0;
  38. }
  39. }
  40. }
  41. }