- Home /
How do I build a GUI that works on different sized screens?
I've been struggling getting Guitext /Guitextures to scale to screen (both for different PC monitors as well as Android Phone Sizes). Could someone please explain to me step by step (or point me to previously made instructions) the basics of building a GUI that works on different screen sizes/aspect ratios.
Answer by Domo23000 · Jan 29, 2014 at 03:58 AM
Try this
GUI.box(Rect( Screen.width/2, Screen.height/2, Screen.width, Screen.height), "Words");
Screen.width measures the width of the screen, and Screen.height does the same but with the height.
for the position, id Screen.width/2 to position it in the center. and the size i just use Screen.width to measure the width and set the size to that.
I have been having the same problem too.I tried the above script and it does not work for me.It puts the box in the lower right hand corner.
I am doing something like this so i will test it and make it work
Screen.width/2 - Screen.width/2
This worked for the position.
Ok I might have been doing something wrong then...Sorry that I questioned your answer.
oh, no I did it wrong, I didn't add ( - Screen.width/2 ) after Screen.width and Screen.height. And don't be sorry, your question helped me fix the answer. :D
Answer by Phenelo · Jan 29, 2014 at 05:12 AM
I'm also a newbie and what I did is I set up an original resolution and used the method here about modifying GUI matrix. Once your settled, draw the GUI's in fixed positions like:
GUI.Box(new Rect(10,10,100,50), "Hey!");
And it will be scaled depending on the GUI matrix if the resolution changed. I think resizing your Game View window to the closest size of your original resolution helps, because it worked for me.
EDIT: SIDE NOTE OnGUI and GUITexture/GUIText are two different Unity GUI Systems.
Answer by Ashish Dwivedi · Jan 30, 2014 at 12:52 PM
You have to calculate your rect by using "Screen.width" and "Screen.height"
Your answer
Follow this Question
Related Questions
How to make GUI Text Scale to different Resolutions? 3 Answers
Scaling a GUI element to fit it's contents 0 Answers
Problem With GUI Circle Thickness 1 Answer
Fix Blurry UI text? 10 Answers