Search code examples
c#unity-game-enginevirtual-realitygear-vr

Unity Gaze Input for GearVR


Okay, so, I got the challenge to create a program, in Unity for GearVR. I have to make a program which makes use of gaze input, so if you stare at an object for several seconds it'll display you a 360* video.

I barely can't find any GearVR Gaze Input tutorials around on the web so I wanted to give it a shot on Stackoverflow, and hopefully someone could help me out! :)


Solution

  • You have to use Physics.Raycast. This method emits a ray from the camera point to the camera orientation. You can use something like that:

    // Does the Ray hit an object with a component named MyObjectScript?
    RaycastHit hit;
    Vector3 fwd = transform.TransformDirection(Vector3.forward);
    if (Physics.Raycast(transform.position, fwd, out hit) )
    {
        var script = hit.transform.GetComponent<MyObjectScript>();
        if (script != null)
        {
            //Do your stuff...
        }
    }
    

    Simply put this script on your camera in the FixedUpdate method and another script named MyObjectScript in the object you want to detect.