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.

51 lines
1.6 KiB

  1. namespace VRTK.Examples.Old
  2. {
  3. using UnityEngine;
  4. public class FireExtinguisher_Base : VRTK_InteractableObject
  5. {
  6. public Animation leverAnimation;
  7. public FireExtinguisher_Sprayer sprayer;
  8. private VRTK_ControllerEvents controllerEvents;
  9. public override void StartUsing(VRTK_InteractUse currentUsingObject = null)
  10. {
  11. base.StartUsing(currentUsingObject);
  12. controllerEvents = currentUsingObject.GetComponent<VRTK_ControllerEvents>();
  13. }
  14. public override void StopUsing(VRTK_InteractUse previousUsingObject = null, bool resetUsingObjectState = true)
  15. {
  16. base.StopUsing(previousUsingObject, resetUsingObjectState);
  17. controllerEvents = null;
  18. }
  19. protected override void Update()
  20. {
  21. base.Update();
  22. if (controllerEvents)
  23. {
  24. float power = controllerEvents.GetTriggerAxis();
  25. Spray(power);
  26. VRTK_ControllerHaptics.TriggerHapticPulse(VRTK_ControllerReference.GetControllerReference(controllerEvents.gameObject), power * 0.25f, 0.1f, 0.01f);
  27. }
  28. else
  29. {
  30. Spray(0f);
  31. }
  32. }
  33. private void Spray(float power)
  34. {
  35. SetHandleFrame(power);
  36. sprayer.Spray(power);
  37. }
  38. private void SetHandleFrame(float frame)
  39. {
  40. leverAnimation["FireExtinguisherLever"].speed = 0;
  41. leverAnimation["FireExtinguisherLever"].time = frame;
  42. leverAnimation.Play("FireExtinguisherLever");
  43. }
  44. }
  45. }