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.

44 lines
981 B

  1. namespace Oculus.Platform.Samples.VrVoiceChat
  2. {
  3. using UnityEngine;
  4. using System.Collections;
  5. using UnityEngine.UI;
  6. // Helper class to attach to the main camera that raycasts where the
  7. // user is looking to select/deselect Buttons.
  8. public class VREyeRaycaster : MonoBehaviour
  9. {
  10. [SerializeField] private UnityEngine.EventSystems.EventSystem m_eventSystem = null;
  11. private Button m_currentButton;
  12. void Update ()
  13. {
  14. RaycastHit hit;
  15. Button button = null;
  16. // do a forward raycast to see if we hit a Button
  17. if (Physics.Raycast(transform.position, transform.forward, out hit, 50f))
  18. {
  19. button = hit.collider.GetComponent<Button>();
  20. }
  21. if (button != null)
  22. {
  23. if (m_currentButton != button)
  24. {
  25. m_currentButton = button;
  26. m_currentButton.Select();
  27. }
  28. }
  29. else if (m_currentButton != null)
  30. {
  31. m_currentButton = null;
  32. if (m_eventSystem != null)
  33. {
  34. m_eventSystem.SetSelectedGameObject(null);
  35. }
  36. }
  37. }
  38. }
  39. }