BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / Platform / Samples / VrHoops / Scripts / VREyeRaycaster.cs

VREyeRaycaster.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
VREyeRaycaster.cs 950 B Download Raw
1namespace Oculus.Platform.Samples.VrHoops
2{
3 using UnityEngine;
4 using UnityEngine.UI;
5
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
12 private Button m_currentButton;
13
14 void Update ()
15 {
16 RaycastHit hit;
17 Button button = null;
18
19 // do a forward raycast to see if we hit a Button
20 if (Physics.Raycast(transform.position, transform.forward, out hit, 50f))
21 {
22 button = hit.collider.GetComponent<Button>();
23 }
24
25 if (button != null)
26 {
27 if (m_currentButton != button)
28 {
29 m_currentButton = button;
30 m_currentButton.Select();
31 }
32 }
33 else if (m_currentButton != null)
34 {
35 m_currentButton = null;
36 if (m_eventSystem != null)
37 {
38 m_eventSystem.SetSelectedGameObject(null);
39 }
40 }
41 }
42 }
43}