- Home /
Scaling GUI When Screen Width is Adjusted
Hi, all! I have looked at the answers to this question many times, but none ever seem to work!
I have made I game. I have designed the GUI to work with 1080 x 1024 resolution screens. My GUI will get squished together or will leave the screen in any other resolution. Is there a way to scale my GUI so that the smaller the screen is, the smaller the GUI (& text inside it) is? The other examples I have seen just position the GUI. :(
Also, I have GUITexture backgrounds. Is there any way for me to make it so that my background image is scaled/stretched to fit the screen?
I really need help here. Any help would be greatly appreciated. Thanks! - YA
maybe you have not seen the correct answer so maybe this is the answer of your problem: http://answers.unity3d.com/questions/21244/gui-postion-affacted-when-$$anonymous$$imize-the-screen/27855#27855
Or maybe not. It doesn't address scaling. The author in that post want to change pixelInset, probably wanting to maintain pixel perfect scale and ins$$anonymous$$d position the elements around.
Answer by Statement · Dec 17, 2010 at 12:00 AM
Yes, you can use GUI.matrix to scale your Gui. However, note that your gui will probably look stretched with other aspect ratios unless you design your gui for each ratio.
Scale x by (Screen.width / 1080) and y by (Screen.height / 1024). Use Matrix4x4.Scale to create the matrix.
I haven't tested it myself but this should work.
Vector3 scale = new Vector3((float)Screen.width / 1080.0f,
(float)Screen.height / 1024.0f,
1.0f);
GUI.matrix = Matrix4x4.Scale(scale);