Hi everyone !
I have a UI in screenspace. I want to scale a UI in worldspace so that it has the same size thant my UI in screenspace. I did that. It worked. I also want to place the worldspace UI at the same position in world than the UI in screenspace. But I can’t do that !
Here a a screenshot so that I can explain myself :
In white on the game window, it is my screenspace UI. I scaled a world UI so that it has the same size than my screen UI.
But I can’t put it at the same position !
Here is my code to get the corners of the screenspace UI in the worldspace :
RectTransform rect = _Panel.GetComponent<RectTransform> ();
Vector3[] corners = new Vector3[4];
rect.GetLocalCorners (corners);
float z = _Distance;
corners [0] = new Vector3 (corners [0].x, corners [0].y, z);
corners [1] = new Vector3 (corners [1].x, corners [1].y, z);
corners [2] = new Vector3 (corners [2].x, corners [2].y, z);
corners [3] = new Vector3 (corners [3].x, corners [3].y, z);
corners [0] = Camera.main.ScreenToWorldPoint (corners [0]);
corners [1] = Camera.main.ScreenToWorldPoint (corners [1]);
corners [2] = Camera.main.ScreenToWorldPoint (corners [2]);
corners [3] = Camera.main.ScreenToWorldPoint (corners [3]);
Gizmos.color = Color.blue;
Gizmos.DrawSphere(corners [0], 0.1f);
Gizmos.DrawSphere(corners [1], 0.1f);
Gizmos.DrawSphere(corners [2], 0.1f);
Gizmos.DrawSphere(corners [3], 0.1f);
The size between the corners is good ! I use it to scale my worldspace UI. But the position is wrong as you can see on the screenshot (blue spheres). Blue spheres should not be here but in front of my camera with the red worldUI.
The worldspace UI is at 3 of distance from my camera. So my variable “float z = _Distance;” that I use in “corners [0] = new Vector3 (corners [0].x, corners [0].y, z);” is 3f.
Thanks for your help !
