Hey guys,
Been playing with a menu system for our game and am having difficulties understanding how to size and position GUI elements.
When viewing everything in ‘Game’ mode, they look positioned correctly, but when playing the export, this is not the case. For example my buttons get thrown waaaay off to the right and half the background image is chopped off.
This is a sample of the code (nothing special) it’s just directly adapted from the 3D platformer tutorial…
What’s going on here? How can I preview what it will ACTUALLY look like when exported?
To my understanding I’m taking the screen’s measurement and adjusting everything to position itself accordingly, but this isn’t the case.
Thanks for any help you can offer here.
@script ExecuteInEditMode()
var gSkin : GUISkin;
var backdrop : Texture2D;
private var isLoading = false;
function OnGUI()
{
if(gSkin)
{
GUI.skin = gSkin;
}
else
{
Debug.Log("StartMenuGUI : GUI Skin object missing!");
}
var backgroundStyle : GUIStyle = new GUIStyle();
backgroundStyle.normal.background = backdrop;
//GUI.Label ( Rect( ( Screen.width - (Screen.height * 2)) * 0.75, 0, Screen.height * 2, Screen.height), "", backgroundStyle); 0.425
GUI.Label ( Rect( ( Screen.width - (Screen.height)) * 0.425, -10, Screen.height * 0.985, Screen.height * 1.025), "", backgroundStyle);
//GUI.Label ( Rect( (Screen.width/2)-250, 50, 400, 100), "what about iggy - iggy's revenge"); // will be an image
//enter game
if(GUI.Button( Rect( (Screen.width/2)+300, Screen.height - 800, 250, 70), "enter game"))
{
isLoading = true;
Application.LoadLevel("LevelOneExterior");
}
//about the game
if(GUI.Button( Rect( (Screen.width/2)+260, Screen.height - 730, 320, 70), "about the game"))
{
isLoading = true;
Application.LoadLevel("AboutMenu");
}
//characters
if(GUI.Button( Rect( (Screen.width/2)+260, Screen.height - 670, 320, 70), "characters"))
{
isLoading = true;
Application.LoadLevel("CharactersMenu");
}
//how to play
if(GUI.Button( Rect( (Screen.width/2)+260, Screen.height - 600, 320, 70), "how to play"))
{
isLoading = true;
Application.LoadLevel("HowToPlayMenu");
}
if(isLoading)
{
GUI.Label ( Rect( (Screen.width/2)-110, (Screen.height / 2) - 60, 400, 70), "loading...", "mainMenuTitle");
}
Backdrop = "iggyHeadHighRes";
}