Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created May 15, 2017 20:06
Show Gist options
  • Save unity3dcollege/cf698402343430c470000dcbe111f4fb to your computer and use it in GitHub Desktop.
Save unity3dcollege/cf698402343430c470000dcbe111f4fb to your computer and use it in GitHub Desktop.
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