BlueGit

blue-star ggj-2020

Files

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

VREyeRaycaster.cs

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