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

Gaze Over, display Tooltip in Unity with GoogleVR


Does any know or can possibly point me to some instructions or a github repository on how I can create a script where I have an object and in GoogleVr (Cardboard) if I was to gaze over an object, a tooltip would appear?

Arctic Fox

If anyone is familiar, in the Cardboard Demos under Under Arctic Journey > Learn, when you click on the fox, a tooltip appears to showcase that item along with like a brief description on it. I want to have something similar (maybe even the same thing) except just having a gaze over will automatically show it. Is this possible?

I want to have this done on multiple objects in my project so I want it created so I can easily substitute out text and whatnot.


Solution

  • Have a script with a reference to a World Space Canvas (WSC). The WSC will be your tooltip and be activated when you hover over the object and disabled when you don't.

    You can set images and texts of the WSC through the inspector or through code if you make a reference to them.

    The script should also always have its rotation set to face the player.

    You can use the SetActive(bool) method to show or hide the WSC.

    The UI system makes it easy to create UI that is positioned in the world among other 2D or 3D objects in the Scene.

    Start by creating a UI element (such as an Image) if you don’t already have one in your scene by using GameObject > UI > Image. This will also create a Canvas for you. Set the Canvas to World Space

    Select your Canvas and change the Render Mode to World Space.

    Now your Canvas is already positioned in the World and can be seen by all cameras if they are pointed at it, but it is probably huge compared to other objects in your Scene. We’ll get back to that.

    https://docs.unity3d.com/Manual/HOWTO-UIWorldSpace.html