- Home /
How to make an object fixed on the screen?
What's up devs! Hope you all doing well!
I'm developing a HoloLens application on Unity and I'm stuck on how to fix a GameObject on the screen. I'm trying to create a menu and fix it on the middle left of my screen. So, even when the person move the HoloLens, the menu will always stay there.
I really don't know what to do. I tried some scripts, but all of them fix the camera and the GameObject. I think the way to do that is to fix limits to the screen (canvas) and then, fix the GameObject on the middle-left of it.
Does anyone knows how to do that? Thanks!
can't you just use a canvas? Or you could set the GOs position based on camera every frame.
You're right. I need to build exactly that. Just don't know why.
Answer by pr_0_0_ · May 18, 2021 at 07:19 PM
Did you try keeping its coordinates relative to the camera?
Just copy this code if you haven't done it yet:
public Transform selectYourCameraHere;
public float xCoordinate, yCoordinate, zCoordinate;
void Update()
{
transform.position = selectYourCameraHere.position + new Vector3 (xCoordinate, yCoordinate, zCoordinate);
}
Attach this script to your object which you want to not change position. Remove the Box Collider also if you don't want it to touch anything.
Your answer
![](https://koobas.hobune.stream/wayback/20220613033905im_/https://answers.unity.com/themes/thub/images/avi.jpg)