Setting up a Simple Gaze Interaction
In today’s blog post, we’ll explore how to set up a simple gaze interaction to improve our escape room.
Note: this article is a continuation of the socket interaction blog post.
Setting up the mirror
Let’s first add an XR Simple Interactable component to the mirror, disable it (because we will enable it by interacting with other objects), set the layer mask to “Gaze,” and make sure that the “Allow Gaze Interaction” box is checked.
After that, drop the keyhole object into the First Hover Entered event field, select the SetActive function, and check the box right below it. By doing this, we will activate the keyhole by interacting with the mirror (make sure that you have the keyhole object deactivated).
Also, make sure that “Is Trigger” is unchecked; otherwise, the gaze interaction won’t work. I’m using version 2022.3.2f1 of Unity, and other versions may require this box to be checked.
Setting up the keyhole
First, drop the mirror object into the Select Entered and Select Exited events. Select the XRSimpleInteractable.enabled function for both and check the box for the former one only so we enable the gaze interaction by wearing the hat and disable it by taking it off.
And here’s our result: