- Home /
GUILayout alignment issue
Hello, I'm currently working on my game menus, and i have a problem. I'm using GUILayout for creating the buttons but i can't figure out how to align the whole thing. I've set the the coordinates of GUILayout.BeginArea to the most centered point i could get, but, on different resolutions, the whole area moves a bit ( right or left, depending on the resolution ). Is there any other way to center this in order to get smoother results ? I've linked some pictures with different resolutions so you can see the actual problem. Also, here's the script of my menu. Maybe i'm doing something wrong.
var menu_skin : GUISkin;
function OnGUI()
{
if (ball_health.game_over == true)
{
GUI.skin = menu_skin;
GUILayout.BeginArea (Rect (Screen.width / 2.8,Screen.height / 2.5,400,500));
//game over text
GUILayout.BeginHorizontal();
GUILayout.Box ("Game Over");
GUILayout.EndHorizontal();
//restart, main menu buttons
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
if (GUILayout.Button ("Restart"))
{
collect_coins.score = 0;
ball_health.game_over = false;
Application.LoadLevel ("level_1");
ball_health.ball_hp = 3;
}
GUILayout.Button ("Options");
GUILayout.EndHorizontal();
GUILayout.EndVertical();
//Options, Quit buttons
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.Button ("Main Menu");
if (GUILayout.Button ("Exit Game"))
{
Application.Quit();
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.EndArea();
}
}
Thanks for your help!
Answer by stevethorne · Mar 13, 2014 at 10:34 PM
GUILayout.BeginArea (Rect (Screen.width / 2.8,Screen.height / 2.5,400,500));
This line is your problem. You're scaling the starting x and y with the screen width and height, but you're not scaling the width and height of the group with the screen width and height.
I'm sorry, but i'm not really getting your answer. Shouldn't the entire group be aligned to the position of the begin area ?
Your answer
Follow this Question
Related Questions
GUILayout element alignment issue 0 Answers
GUILayout.Label alignment / spacing 1 Answer
GUI content horizontal alignment 2 Answers
how to transform vector3 input relative to the surface? 1 Answer