- Home /
How to posistion GUI elements?
The problem I am having is the time bar is interfering with the max players bar http://prntscr.com/50kgq5 Here is part of the script
GUILayout.BeginHorizontal();
GUILayout.Label("Max Players: ", GUILayout.Width(130));
// Select Round Duration Time
GUILayout.Space(5);
GUILayout.BeginHorizontal();
GUILayout.Label("Time", GUILayout.Width(130));
for(int i = 0; i < maxTimeOptions.Count; i++){
if(roundDuration == maxTimeOptions[i]){
//Selected number is green
GUI.color = Color.green;
}else{
GUI.color = Color.white;
}
if(GUILayout.Button(maxTimeOptions[i].ToString(), GUILayout.Width(45), GUILayout.Height(28))){
roundDuration = maxTimeOptions[i];
}
}
GUI.color = Color.white;
GUILayout.EndHorizontal();
for(int i = 0; i < maxPlayersOptions.Count; i++){
if(maxPlayers == maxPlayersOptions[i]){
//Selected number is green
GUI.color = Color.green;
}else{
GUI.color = Color.white;
}
if(GUILayout.Button(maxPlayersOptions[i].ToString(), GUILayout.Width(27), GUILayout.Height(25))){
maxPlayers = maxPlayersOptions[i];
}
}
GUI.color = Color.white;
GUILayout.EndHorizontal();
Please help me fix this
How is the time bar interfering with the max players bar? Where should it be placed ins$$anonymous$$d? Does that dark rectangle near the center have any significance? Please provide some more info :)
The time is ment to be bellow the max players. The dark rectangle is just a demo, when it's finished it will ba a pictur of a map
Answer by Teal · Oct 29, 2014 at 05:06 AM
Change
GUILayout.Label("Max Players: ", GUILayout.Width(130));
to this
GUI.Label(new Rect(From Left, From Top, Width, Height), "Text");
Here is the script for it, Look on the unity website more, it is really helpful
P.s. May be a bit harder at the beginning due to scaling, but with a bit of practice GUI can be made simple
Have fun
I'm actually not too bad with GUI, but I'm use to JS and a friend of $$anonymous$$e is looking me to fix a script in C# which is why I'm having a bit of bother