What I am looking for is probably fairly simple, but I am new in Unity so I need your help if anyone knows.
I am building a VR app and upon some interaction with objects I want a popup menu to appear in front of the camera and when I look away the popup closes .
I have my popup as a child of main camera which is probably wrong because that way it is attached to where the camera is looking. I fixed this by assigning a variable position = transform.position on Start() and then on Update(), transform.position = position. Yet again if I look down on an object and interact the popup will probably be clipping on the ground.
I tried not to have the popup as a Camera child but then I couldn’t position it properly in front of the camera when appearing.
Anyone knows the best approach to this? Thanks in advance.
where cameraToAppearInFrontOf and distanceFromCamera are pretty self-explanatory variables and adding an EventTrigger Pointer Exit to set to inactive when gaze away.
So I just did this in my own project to make a menu pop up in front of the camera. The easiest way I have found to accomplish this is to create an empty game object, and put it as a child of the camera and putting the z to like 4 so it will always be right in front of the camera. then on click I change the position and rotation of my menu to the position and rotation of my spawn point.
public GameObject spawn;
public GameObject popup;
if (Input.GetMouseButtonDown(0))
{
popup.transform.position = spawn.transform.position;
popup.transform.rotation = spawn.transform.rotation;
}
I’m sure you can do something where you get position of the camera and just add 4 to the z vector, if that would make more sense to you.
for making it go away you will have to use a gaze command and move the menu or use GameObject.SetActive to hide it until its used again.