- Home /
Correct usage of GUILayout.BeginVertical
So I''m having a problem setting up GUI interface, placing elements where I want them..
I get nothing on-screen when the button Show Server Logs is pressed, I read up about the GUILayour tutorial but still can't wrap my head around it..
Is there something I am doing wrong? Should I place the GUILayout.BeginVertical somewhere else in the OnGUI()?
void OnGUI()
{
GUILayout.BeginArea(new Rect(10, 10, Screen.width, Screen.height));
if (Network.peerType == NetworkPeerType.Disconnected)
{
if (GUILayout.Button("Start Server", GUILayout.Width(120), GUILayout.Height(25)))
{
Network.InitializeSecurity();
Network.InitializeServer(_maxConnections, _serverPort, true);
Debug.Log("Server is starting up..");
}
}
else
{
if (GUILayout.Button("Show Server Logs", GUILayout.Width(120), GUILayout.Height(25)))
{
Debug.Log("Showing server logs.");
GUILayout.BeginVertical();
GUILayout.Box("Server Console" + _serverMessages, GUILayout.Width(Screen.width), GUILayout.Height(200));
GUILayout.EndVertical();
}
if (GUILayout.Button("Shutdown Server", GUILayout.Width(120), GUILayout.Height(25)))
{
Network.Disconnect(500);
Debug.Log("Server is shutting down..");
}
}
GUILayout.EndArea();
}
Answer by perchik · Sep 04, 2013 at 05:22 PM
Well in this case, you're not actually doing anything with BeginVertical(), which is used to automatically lay out a bunch of items in a vertical column (one under each other), but since you only have one item in the vertical layout section, it's not going to do anything at all.
I'd try getting rid of the GUILayout.Width()
and GUILayout.height()
calls and see if it works (but with the wrong sizes). If it does, I'd wager that your sizes are causing it to fall off the screen or something.
Hi Perchik, thanks for the reply.
I have tried it several times without the GUILayout.width and GUILayout.height calls. But I think I got some confusion as to how it's all working together, since the GUILayout tutorial page, shows all three in use. BeginArea() to wrap an entire GUI area, inside first being called Horizontal, then a button then the Vertical, then both groups are closed and so is the area. What I don't understand is why the box doesn't show up at all, even tried it with and without GUILayout.width/height.