241
NGUI 3 Support / Searching for UILabels in an object by name?
« on: May 09, 2012, 01:05:32 AM »
Is there anyway to get an object in the Menu list by name? So far I have my default menu that I am spawning from a prefab. I can change the text ok but to get to the objects I am doing something like
window_name = theMenu.GetComponentsInChildren<UILabel>()[0];
main_body = theMenu.GetComponentsInChildren<UILabel>()[1];
Now this works only because of the current order of the menu and is not really that stable, if I add a button or want to change my menu, it will probably find the UILabel from somewhere else instead of what I am expecting. What I am really trying to do is something like this:-
window_name = theMenu.GetComponent("Window Name");
main_body = theMenu.GetComponent("Main Body");
Thanks for reading.
window_name = theMenu.GetComponentsInChildren<UILabel>()[0];
main_body = theMenu.GetComponentsInChildren<UILabel>()[1];
Now this works only because of the current order of the menu and is not really that stable, if I add a button or want to change my menu, it will probably find the UILabel from somewhere else instead of what I am expecting. What I am really trying to do is something like this:-
window_name = theMenu.GetComponent("Window Name");
main_body = theMenu.GetComponent("Main Body");
Thanks for reading.