- Home /
Placing GUI elements?
Hello. I developed my game's GUI using absolute positions. At the 3:2 aspect ratio, everything looks fine. But, because I used absolute positions, any other resolution does not work properly with the GUI. Rather than go back and replace all of the GUI elements with relative positions manually, I was told Unity is able to do it automacily using this code. But I dont understand exactly what the person who posted the code meant, can someone please elaborate on it(here is the code and the persons explanation)?
Vetor3 scale = new Vector3(origWidth
/Screen.width, origHeight /
Screen.height, 1); GUI.matrix
=Matrix4x4.Scale(scale);
where origWidth and origHeight is the screen size you used when designing the gui you can design you gui in the editor, using a good screen size (e.g. 1920x1200) using absolute positions like you would normally do. Then all you have to do is tell the script the original used screen size and will do the scaling for you. No extra code needed.
Answer by efge · Feb 25, 2011 at 12:42 PM
He divides the "design" width and height with the current width and height of the screen window and feeds the scaling part of the standard 4x4 transformation matrix for the GUI.
So when your GUI was designed at a resolution of 1920x1200 (origWidth x origHeight) and the user resizes the window to a smaller size, the GUI will be scaled accordingly.
Your answer
Follow this Question
Related Questions
Is this the correct way to scale my GUI? 1 Answer
Android screen size script not working 1 Answer
Resolution of Unity 3d GUI button 1 Answer
OnGUI Button 1 Answer
Resize GUI for older iPhone versions 2 Answers