Created
May 15, 2017 20:06
-
-
Save unity3dcollege/cf698402343430c470000dcbe111f4fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class GazeInput : MonoBehaviour | |
{ | |
private Ray ray; | |
private RaycastHit hitInfo; | |
[SerializeField] | |
[Tooltip("The root object of all menu items")] | |
private GameObject menuRoot; | |
private void Update() | |
{ | |
if (Input.GetMouseButtonDown(0)) | |
{ | |
if (menuRoot.activeInHierarchy == false) | |
{ | |
ShowMenu(); | |
} | |
else | |
{ | |
TrySelectMenuItem(); | |
} | |
} | |
} | |
private void TrySelectMenuItem() | |
{ | |
ray = new Ray(transform.position, transform.forward); | |
if (Physics.Raycast(ray, out hitInfo)) | |
{ | |
var videoSelection = hitInfo.collider.GetComponent<VideoSelection>(); | |
if (videoSelection != null) | |
{ | |
videoSelection.StartClipIfNotAlreadyPlaying(); | |
HideMenu(); | |
} | |
} | |
else | |
{ | |
HideMenu(); | |
} | |
} | |
private void ShowMenu() | |
{ | |
menuRoot.SetActive(true); | |
} | |
private void HideMenu() | |
{ | |
menuRoot.SetActive(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment