- Home /
Question by
Babu234664 · Jul 13, 2014 at 11:25 AM ·
guitextwindowscreen size
How to make a GUI fit any screen sizes?
Hello, guys I'm having some problem with a script. I have this javascript code:
var GameName : String = "Game Name";
var GameType : int = 0;
var selStrings : String[] = ["Fighting", "Race", "MOBA", "FPS"];
function OnGUI(){
GameCreater();
FinishedWithGame();
GType();
}
function GameCreater() {
GameName = GUI.TextField (Rect (300, 135, 200, 20), GameName, 25);
}
function GType() {
GameType = GUI.SelectionGrid (Rect (325,175, 150, 100), GameType, selStrings, 2);
}
function FinishedWithGame(){
if(GUI.Button(Rect(385,350,50,20), "Finish")){
SaveGame();
}
}
function SaveGame(){
Debug.Log("Saving Game...");
PlayerPrefs.SetString("Game_Name", GameName);
}
And I have to make it responsive. I mean, when someone plays it in a 1280x1024 screen, it has to be centered as if it was in a 1024x728 monitor. Can you guys help me please? :)
Thanks.
Comment
Answer by YoungDeveloper · Jul 13, 2014 at 11:28 AM
private var rect_test:Rect;
function Start(){
rect_test = new Rect(0,0, 300,100);
rect_test.center = new Vector2(Screen.width/2, Screen.height/2);
//OR
//rect_test = new Rect(Screen.width/2 - 150, Screen.height/2 - 50, 300,100);
}
function OnGUI(){
GUI.Box(rect_test, "");
}
This will always be in the center of screen.
you could also size your rect to Screen.width*.4, etc. then you can build all objects by percentages, but the text doesn't always like it.