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.

46 lines
1.7 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. public class RC_Car_Controller : MonoBehaviour
  5. {
  6. public GameObject rcCar;
  7. private RC_Car rcCarScript;
  8. private void Start()
  9. {
  10. rcCarScript = rcCar.GetComponent<RC_Car>();
  11. GetComponent<VRTK_ControllerEvents>().TriggerAxisChanged += new ControllerInteractionEventHandler(DoTriggerAxisChanged);
  12. GetComponent<VRTK_ControllerEvents>().TouchpadAxisChanged += new ControllerInteractionEventHandler(DoTouchpadAxisChanged);
  13. GetComponent<VRTK_ControllerEvents>().TriggerReleased += new ControllerInteractionEventHandler(DoTriggerReleased);
  14. GetComponent<VRTK_ControllerEvents>().TouchpadTouchEnd += new ControllerInteractionEventHandler(DoTouchpadTouchEnd);
  15. GetComponent<VRTK_ControllerEvents>().ButtonTwoPressed += new ControllerInteractionEventHandler(DoCarReset);
  16. }
  17. private void DoTouchpadAxisChanged(object sender, ControllerInteractionEventArgs e)
  18. {
  19. rcCarScript.SetTouchAxis(e.touchpadAxis);
  20. }
  21. private void DoTriggerAxisChanged(object sender, ControllerInteractionEventArgs e)
  22. {
  23. rcCarScript.SetTriggerAxis(e.buttonPressure);
  24. }
  25. private void DoTouchpadTouchEnd(object sender, ControllerInteractionEventArgs e)
  26. {
  27. rcCarScript.SetTouchAxis(Vector2.zero);
  28. }
  29. private void DoTriggerReleased(object sender, ControllerInteractionEventArgs e)
  30. {
  31. rcCarScript.SetTriggerAxis(0f);
  32. }
  33. private void DoCarReset(object sender, ControllerInteractionEventArgs e)
  34. {
  35. rcCarScript.ResetCar();
  36. }
  37. }
  38. }