- Home /
Adjust a Plane to specific Screen postition (Sync with GUI Elemnt)
Hey there,
so i try to place a Plane as a GUI element So i placed a second Cam. Set the settingt to ortographic and rendered my Plane. Everthing ist good except that the plane and my UI are not synced in Screenspace when i change the Screen.width / height. I have no idee how to archive this. How can i force the plane to be everytime rendered at the same Screen X / Y Position ?
Need i to adjust Cam settings or did i need to change the plane position to a specific screen Position ? What is the simplest / solid way to archive this ?
Thanks & Greetings
Lukas
Answer by robertbu · May 27, 2013 at 06:21 AM
There are four coordinates systems in Unity, World, Screen, Viewport and GUI. I'm going to assume you have are using GUI and Rects to output your GUI elements. You can position a 3D world object at a GUI coordinate by 1) Converting that coordinate to a Screen coordinate, and then 2) converting the Screen coordinate to a World coordinate. Note World coordinates are in 3D space, so you have to specify the distance in front of the camera when you do the Screen to World conversion. So if we had a GUI coordinate at (200, 300):
var v3GUI = Vector3(200,300,0);
var v3Screen = GUIUtility.GUIToScreenPoint(v3GUI);
v3Screen.z = 10; // Picking 10 units in front of the camera
var v3World = Camera.main.ScreenToWorldPoint(v3Screen);
Your response wasnt right but you point me in the right direction.
Now i am able to place the Sphere at a specific position in the guy.
v3GUI = new Vector3(Screen.width / 2, 100 ,0); v3GUI.z = 20; v3Screen = GUIUtility.GUIToScreenPoint(v3GUI); transform.position = GameObject.Find("SphereCam").camera.ScreenToWorldPoint(v3GUI);
But when i reduce the size of my preview windows the Sphere is beeing streched / Shrinked. How can i "lock" the size of the Sphere ? I guese i need to Scale it ?
greetings
Lukas
Nothing here should scale your sphere. Is this a perspective issue?
It is beeing scalled because the ortograpic camara is beeing scalled down. $$anonymous$$y interface is cut ins$$anonymous$$d. So the size of the 3d area is beeing changed.
I can post some screens later.
You will likely get more and faster responses if you open up this new issue as a new question. We try to keep questions to a single issue.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
HorizontalScrollbar not appearing in GUILayout.BeginScrollview C# 3 Answers
3D Button? 1 Answer
GUI.enabled ? 0 Answers
Limit on GUI Components? 0 Answers