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.

59 lines
1.7 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. public class Controller_Menu : MonoBehaviour
  5. {
  6. public GameObject menuObject;
  7. private GameObject clonedMenuObject;
  8. private bool menuInit = false;
  9. private bool menuActive = false;
  10. private void Start()
  11. {
  12. GetComponent<VRTK_ControllerEvents>().ButtonTwoPressed += new ControllerInteractionEventHandler(DoMenuOn);
  13. GetComponent<VRTK_ControllerEvents>().ButtonTwoReleased += new ControllerInteractionEventHandler(DoMenuOff);
  14. menuInit = false;
  15. menuActive = false;
  16. }
  17. private void InitMenu()
  18. {
  19. clonedMenuObject = Instantiate(menuObject, transform.position, Quaternion.identity) as GameObject;
  20. clonedMenuObject.SetActive(true);
  21. menuInit = true;
  22. }
  23. private void DoMenuOn(object sender, ControllerInteractionEventArgs e)
  24. {
  25. if (!menuInit)
  26. {
  27. InitMenu();
  28. }
  29. if (clonedMenuObject != null)
  30. {
  31. clonedMenuObject.SetActive(true);
  32. menuActive = true;
  33. }
  34. }
  35. private void DoMenuOff(object sender, ControllerInteractionEventArgs e)
  36. {
  37. if (clonedMenuObject != null)
  38. {
  39. clonedMenuObject.SetActive(false);
  40. menuActive = false;
  41. }
  42. }
  43. private void Update()
  44. {
  45. if (clonedMenuObject != null && menuActive)
  46. {
  47. clonedMenuObject.transform.rotation = transform.rotation;
  48. clonedMenuObject.transform.position = transform.position;
  49. }
  50. }
  51. }
  52. }