- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
narthur157 · Jul 26, 2012 at 04:20 PM ·
javascriptguimenu
Web player screen resolution GUI placement
I made a game following the walker boys tutorial (here) The menu loads centered correctly if you run the game in the editor or as a standalone. However as you can see in the web player it goes to the bottom right.
Here's what I used to center the menus.
// Main Menu script
private var coordX:int = 300;
private var coordY:int = 60;
var the_text:String;
function Start() {
coordX = Screen.currentResolution.width/2 -60;
coordY = Screen.currentResolution.height/2 - 120;
the_text = "WELCOME TO CLICK";
}
function OnGUI () {
GUI.Label(Rect(coordX+20, coordY, 400,400), the_text);
if (GUI.Button(Rect(coordX,coordY+50,170,60), "Start Game")) {
//print("Start Game");
Application.LoadLevel("sceneLevel1"); // starts level 1
}
if (GUI.Button(Rect(coordX,coordY+120,170,60), "Exit Game")) {
print("Exit Game");
Application.Quit(); // ends the game
}
}
Comment
Answer by whydoidoit · Jul 26, 2012 at 10:43 PM
You want to use Screen.width and Screen.height not currentResolution.xxxx as that will return the resolution of the display not the area in which the game is played on that display.
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Stat bars in Menu system? 1 Answer
dropdown menu error 1 Answer
Making a Pause Menu 1 Answer
Menu Button help 1 Answer