Hello, I’m diving into Unity and I’m trying to dynamically build a GUI based on game data, but only some of the buttons respond to clicks. Below is my code. The buttons being generated in the loop are the buttons that don’t respond to my clicks, but all the buttons that are created outside of the loops do respond to click events. What gives?
void OnGUI () {
// Make a background box
GUI.Box(new Rect(10,10,800,600), “Multiplayer Games”);
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (new Rect (20,40,100,20), "Join Game")) {
Application.LoadLevel(1);
}
// Make the second button.
if (GUI.Button (new Rect (130,40,100,20), "Refresh List")) {
RefreshButtonPressed();
}
// Make the second button.
if (GUI.Button (new Rect (700,40,100,20), "Create Game")) {
Application.LoadLevel("Server");
}
string textAreaString = GUI.TextArea(new Rect (20,70,780,520), " Server Name Player Count IP Address Port");
// THESE BUTTONS DON'T RESPOND TO CLICKS
// Make the buttons for the game servers
for (int i=0; i< _gameServerList.Count; i++)
{
Hashtable table = ((Hashtable) _gameServerList*);*
-
string serverName = (string)table["name"];*
-
double port = (double)table["port"];*
-
double id = (double)table["id"];*
-
string ipaddress = (string)table["ip_address"];*
-
double playerCount = (double)table["player_count"];*
-
string buttonLabelText = string.Format("{0} {1} {2} {3}", serverName, playerCount, ipaddress, port);*
_ if (GUI.Button (new Rect (21,i*40+91,778,40), buttonLabelText)) //<----_
-
{*
-
Client.serverIP = ipaddress;*
-
Client.serverPort = (int)port;*
-
Application.LoadLevel("Client");*
-
}*
-
}*
- }*
Thanks is advance for all your wisdom!