03-03-2022 06:04 AM
I want to display small Unity UI elements to the player that can change dynamically. I at first tried to just use a canvas set to screen space but it didn't render to the screen. I tried to use the OVR Overlay except I can't figure out how to make it lock to the player's head. Are there any solutions to the problem I am trying to solve?
(Using Oculus Quest 2)
03-15-2022 02:40 PM
Here's what I do.
1. Create a new GameObject, call it whatever it is (position 0,0,0).
2. Inside that, create another GameObject, call it Offset for clarity (position this to where you want things in #3 to be as a group, see notes below).
3. Put whatever you want to display in the Offset GameObject (position them relative to offset, they will keep the formation).
Then, add a script to the root GameObject with this in Update:
gameObject.transform.rotation = Camera.main.transform.rotation;
gameObject.transform.position = Camera.main.transform.position;
That keeps the root in the same place with respect to the camera view/rotation.
Then, use the Offset to position the entire group (#3 items). The root position will update frame-by-frame, but the Offset will stay the same, so it can be used in run mode to adjust the position to you liking (otherwise you have to get an initial distance on Start and then and project the gameobject forward every frame, and the position changes every frame so you can't adjust the offset).
It should look something like this, here's my UI setup: