Using GameObject in place of GUI Window. Need help with coordinates

Hey, I created a GameObject to act as the inventory in my 3D Game. I need to lock the object to act as if it were a GUI Window. As in, always in the same spot on the screen unless the user drags the window to a new spot. Right now I’m trying to use this.

transform.eulerAngles = gameCamera.transform.eulerAngles;
Vector3 camPos = gameCamera.transform.position;
camPos.z -= 2;
transform.position = camPos;

Is there a way to lock it to the camera, so that it looks and behaves like a GUI window? It currently stutters when the camera is moved and moves across the screen when the camera view is changed. Please let me know if I need to clarify anything further. Thanks for reading this and to everyone that helps out!

Try putting this code in LateUpate() rather than in Update(). In addition you can do:

transform.rotation = gameCamera.transform.rotation;

Another way to get this functionality is to just make this object a child of the camera. You can either do it ahead of time in the editor, or you can do it dynamically while running.

transform.parent = gameCamera.transform;