I am dynamically creating a new UIButton for each available server in a UIGrid using the following code. After creating the button I want to add the name of the server as the text on the button.
void Start ()
{
GameObject grid = GameObject.Find("ChildGrid");
List<ServerList.Entry> list = TNLobbyClient.knownServers.list;
for(int i = 0 ; i < list.size ; i++)
{
//instantiate a new button and give it the server name
GameObject newBtn = NGUITools.AddChild(grid, btn);
grid.GetComponent<UIGrid>().Reposition ();
//add server name to button
It would seem that there should be a way to access the label directly since the button object is known. I've tried UILabel testObj = newBtn.GetComponent<UILabel>(); but that gives an error.
Is there a way to access this directly or is it necessary to use find?