- Home /
How do I keep GUI Buttons one size?
Hi.
I made a working level select menu but I have a problem.
the buttons aren't the same width.
As you can see, some are wider than others. So does anyone have a method to stop buttons from changing the width?
This is the code I use for each row(Just copied the first horizontal row into here)
//START1-----------------------------------------------------------------------------------------------------
GUILayout.BeginHorizontal();
GUI.skin = MenuGUISkin;
if(GUILayout.Button("Level-1", GUILayout.Height(buttonHeight)))
{
Application.LoadLevel("Level_1");
audio.PlayOneShot(clickSound);
}
//Level 2
if(levelReached >= 2)
{
GUI.skin = MenuGUISkin;
if(GUILayout.Button("Level-2", GUILayout.Height(buttonHeight)))
{
Application.LoadLevel("Level_2");
audio.PlayOneShot(clickSound);
}
}
else
{
GUI.skin = lockedLevels;
if(GUILayout.Button("Level-2", GUILayout.Height(buttonHeight)))
{
audio.PlayOneShot(clickSound);
}
}
//Level 3
if(levelReached >= 3)
{
GUI.skin = MenuGUISkin;
if(GUILayout.Button("Level-3", GUILayout.Height(buttonHeight)))
{
Application.LoadLevel("Level_3");
audio.PlayOneShot(clickSound);
}
}
else
{
GUI.skin = lockedLevels;
if(GUILayout.Button("Level-3", GUILayout.Height(buttonHeight)))
{
audio.PlayOneShot(clickSound);
}
}
GUILayout.EndHorizontal();
//END1-------------------------------------------------------------------------------------------------------
Answer by Fabkins · Jan 15, 2014 at 06:56 PM
You could set the button width in the same way as you fixed the height. eg. GUILayout.Width(buttonWidth).
Looking at your layout however I would be tempted to just used a GUILayout.SelectionGrid
but if I make a GUILayout.SelectionGrid can I then control what each button does and the GUI Skin of the locked levels?
Yes, GUILayout.SelectionGrid can do different things according to which button is pressed, have switch statement on the return value of the call. But you cant change the styles, least that I know of, of individual buttons which means it isnt going to work in your case.
Your answer
Follow this Question
Related Questions
Retreive the Width Delta of a ContentSizeFitter game object 0 Answers
Increase text size over time c# 2 Answers
Multiple Cars not working 1 Answer
How do you change the size and color of a GUI Label in C#? 4 Answers
Distribute terrain in zones 3 Answers