- Home /
Simple GUI question.
I'm sure its an easy thing to do, but for some reason i forgot what I am doing wrong. How can I make it to where the gui doesnt go off screen when viewed in different resolutions? If I set it up to fit my game view in the editor, when its on my android its way too big and can't see half of the gui
Answer by Landern · Sep 11, 2014 at 04:30 AM
If using 4.6, use the Reference Resolution component.
if using < 4.6(old OnGUI system) you will want to use a ratio of the current screen resolution or modify the GUI.matrix.
links to the same question with answers:
http://answers.unity3d.com/questions/156619/scaling-the-gui-with-different-screen-resolutions.html
http://answers.unity3d.com/questions/150736/script-gui-units.html
http://answers.unity3d.com/questions/307330/gui-scale-guis-according-to-resolution.html
http://answers.unity3d.com/questions/156619/scaling-the-gui-with-different-screen-resolutions.html
Answer by MichaelARoberts · Sep 11, 2014 at 04:33 AM
You can either use a matrix (something I still haven't done) which is talked about here
or can use something like this code here. Shown in javascript but works the same way C#.
#pragma strict
function OnGUI ()
{
GUI.Box(Rect(Screen.width,Screen.height,0,0), "A Text Filled Box");
}
by using Screen.width and Screen.height unity grabs the size of your screen and scales it accordingly.
Of course, in 4.6 Unity's GUI scales automatically (I believe, haven't used it all too much yet) with the new canvas system.
For further reading on the old GUI (the one you are probably using): click here
Yes, tried that. But.. still doesnt work properly when having more than one item. Also if the font is large, it doesnt shrink with the screen
Answer by theultimatepwn · Sep 11, 2014 at 05:57 AM
A little script that might help you,
function OnGUI() {
GUI.Box (new Rect((Screen.width / 2) - 100 , 0, 200, Screen.height), "Insert Random Text");
}
Notice the Screen.width and Screen.Height, It is necessary in most cases for a nice GUI that is compatible with multiple platforms. But don't hold any of this against me, GUIs are not my strong point. Anyway.. Good luck to you with your game, I hope that I helped.
,I would suggest reading the documentation on GUIs in Unity, it helped me a lot when I first started doing GUIs. (GUI Scripting Guide)
Your answer
Follow this Question
Related Questions
GUI Resolution Ajust 1 Answer
Scaling GUI correctly according to game window resolution? 1 Answer
How do I Scale a GUITexture or GUIText for different resolutions screen sizes on the iPhone? 1 Answer
Android GUI resize problem 1 Answer
Bulletproof way to do resolution independant GUI scaling? 2 Answers