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.

49 lines
1.5 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. using VRTK;
  5. public class UseRotate : VRTK_InteractableObject
  6. {
  7. [Header("Rotation when in use")]
  8. [SerializeField]
  9. [Tooltip("Rotation speed when not in use (deg/sec)")]
  10. private float idleSpinSpeed = 0f;
  11. [SerializeField]
  12. [Tooltip("Rotation speed when in use (deg/sec)")]
  13. private float activeSpinSpeed = 360f;
  14. [Tooltip("Game object to rotate\n(leave empty to use this object)")]
  15. [SerializeField]
  16. private Transform rotatingObject;
  17. [SerializeField]
  18. private Vector3 rotationAxis = Vector3.up;
  19. private float spinSpeed = 0f;
  20. public override void StartUsing(VRTK_InteractUse currentUsingObject = null)
  21. {
  22. base.StartUsing(currentUsingObject);
  23. spinSpeed = activeSpinSpeed;
  24. }
  25. public override void StopUsing(VRTK_InteractUse previousUsingObject = null, bool resetUsingObjectState = true)
  26. {
  27. base.StopUsing(previousUsingObject, resetUsingObjectState);
  28. spinSpeed = idleSpinSpeed;
  29. }
  30. protected void Start()
  31. {
  32. if (rotatingObject == null)
  33. {
  34. rotatingObject = transform;
  35. }
  36. spinSpeed = idleSpinSpeed;
  37. }
  38. protected override void Update()
  39. {
  40. base.Update();
  41. rotatingObject.Rotate(rotationAxis, spinSpeed * Time.deltaTime);
  42. }
  43. }
  44. }