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
Landern
3
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:
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
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)