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.

61 lines
1.8 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. public class Zipline : VRTK_InteractableObject
  5. {
  6. [Header("Zipline Options", order = 4)]
  7. public float downStartSpeed = 0.2f;
  8. public float acceleration = 1.0f;
  9. public float upSpeed = 1.0f;
  10. public Transform handleEndPosition;
  11. public Transform handleStartPosition;
  12. public GameObject handle;
  13. private bool isMoving = false;
  14. private bool isMovingDown = true;
  15. private float currentSpeed;
  16. public override void OnInteractableObjectGrabbed(InteractableObjectEventArgs e)
  17. {
  18. base.OnInteractableObjectGrabbed(e);
  19. isMoving = true;
  20. }
  21. protected override void Awake()
  22. {
  23. base.Awake();
  24. currentSpeed = downStartSpeed;
  25. }
  26. protected override void Update()
  27. {
  28. base.Update();
  29. if (isMoving)
  30. {
  31. Vector3 moveAmount;
  32. if(isMovingDown)
  33. {
  34. currentSpeed += acceleration * Time.deltaTime;
  35. moveAmount = Vector3.down * currentSpeed * Time.deltaTime;
  36. }
  37. else
  38. {
  39. moveAmount = Vector3.up * upSpeed * Time.deltaTime;
  40. }
  41. handle.transform.localPosition += moveAmount;
  42. if((isMovingDown && handle.transform.localPosition.y <= handleEndPosition.localPosition.y) ||
  43. (!isMovingDown && handle.transform.localPosition.y >= handleStartPosition.localPosition.y))
  44. {
  45. isMoving = false;
  46. isMovingDown = !isMovingDown;
  47. currentSpeed = downStartSpeed;
  48. }
  49. }
  50. }
  51. }
  52. }