Created
November 1, 2017 16:32
-
-
Save jazzyjackson/e16cfa299527aa26c53ca672b4bce1c9 to your computer and use it in GitHub Desktop.
This file contains 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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Controller : MonoBehaviour | |
{ | |
public string selection; | |
// Use this for initialization | |
void Awake() | |
{ | |
selection = null; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
// in Hololens project, the Camera represents your gaze | |
// Camera.main.transform.forward is a normal vector representing which way hololens is pointing ('gaze') | |
var headPosition = Camera.main.transform.position; | |
var gazeDirection = Camera.main.transform.forward; | |
RaycastHit hitInfo; | |
// Check if Ray is colliding with anything, if it hits something, store reference in hitInfo | |
if (Physics.Raycast(headPosition, gazeDirection, out hitInfo)) | |
{ | |
var topOfLabel = hitInfo.collider.gameObject; | |
var thisBox = topOfLabel.transform.GetChild(1).gameObject; | |
selection = topOfLabel.name; | |
// Might be a better way to do this, I'm just iterating through | |
// list of all boxes and deactivating them. Could probably keep a reference to selected box and just deactivate that. | |
var allBoxes = GameObject.FindGameObjectsWithTag("box"); | |
foreach (GameObject box in allBoxes) | |
{ | |
box.SetActive(false); | |
} | |
// before activating the box that my gaze collides with | |
thisBox.SetActive(true); | |
// for debugging, print label of whatever object I'm looking at | |
print(selection); | |
} | |
else | |
{ | |
print("no hit"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment