x


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

more ▼

asked Dec 16 '10 at 11:44 PM

Youngapprentice gravatar image

Youngapprentice
108 21 26 27

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-minimize-the-screen/27855#27855

Dec 17 '10 at 12:00 AM Uriel_96

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 instead position the elements around.

Dec 17 '10 at 12:09 AM Statement ♦♦
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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);
more ▼

answered Dec 17 '10 at 12:00 AM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3689
x388
x381

asked: Dec 16 '10 at 11:44 PM

Seen: 2627 times

Last Updated: Dec 17 '10 at 02:18 AM