- Home /
Question by
frankyboy450 · Oct 02, 2013 at 08:38 PM ·
guibuttons
How do I place 2 buttons next to each other?
Hi. I wrote a function called "MainMenuWindow" and in my OnGUI Function it creates a rect with the function inside. I can't figure out how to make 2 buttons next to each other in my code. does anyone have any ideas?
void MainMenuWindow(int windowID)
{
GUILayout.Label(gameName);
//GUILayout.Label("A game about something");
GUILayout.Space(40);
//The player disconnects from the server when they press the
//disconnect button.
if(GUILayout.Button("Continue", GUILayout.Height(buttonHeight)))
{
Debug.Log("Continue");
audio.PlayOneShot(clickSound);
}
GUILayout.Space(10);
if(GUILayout.Button("Level Select", GUILayout.Height(buttonHeight)))
{
Debug.Log("Level Select");
audio.PlayOneShot(clickSound);
}
GUILayout.Space(10);
if(GUILayout.Button("Help", GUILayout.Height(buttonHeight)))
{
Debug.Log("Help");
audio.PlayOneShot(clickSound);
}
GUILayout.Space(10);
if(GUILayout.Button("Options", GUILayout.Height(buttonHeight)))
{
Debug.Log("Options");
audio.PlayOneShot(clickSound);
showMainMenuWindow = false;
showOptionsWindow = true;
}
GUILayout.Space(10);
if(GUILayout.Button("Quit", GUILayout.Height(buttonHeight)))
{
audio.PlayOneShot(clickSound);
Application.Quit();
}
}
void OnGUI ()
{
if(showMainMenuWindow == true)
{
GUI.skin = _GUISkin;
mainMenuWindowRect = new Rect(Screen.width / 2 - mainMenuWindowWidth / 2, Screen.height / 2 - mainMenuWindowHeight / 2,
mainMenuWindowWidth, mainMenuWindowHeight);
mainMenuWindowRect = GUILayout.Window(1, mainMenuWindowRect, MainMenuWindow, "");
}
}
Comment
Best Answer
Answer by TrickyHandz · Oct 03, 2013 at 01:31 AM
You if you want stuff side-by-side use GUILayout.BeginHorizontal(). Here's the link to the docs on it: GUILayout.BeginHorizontal()
EDIT: Fixed link to wrong version of BeginHorizontal Docs
Your answer
Follow this Question
Related Questions
loop GUI Buttons doesn`t respond 0 Answers
Control script generated buttons with a Gamepad 0 Answers