Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: WUTAI on October 24, 2013, 09:08:13 PM

Title: Access to object thats been added using NGUITools.AddChild()
Post by: WUTAI on October 24, 2013, 09:08:13 PM
HI

I have created a UILabel using NGUITools.AddChild(GameObject.Find("Panel"), myObject);
How can I access that new label to modify the text?

Thanks.
Title: Re: Access to object thats been added using NGUITools.AddChild()
Post by: ArenMook on October 24, 2013, 09:20:36 PM
Well first of all, never use GameObject.Find. It's SUPER slow, and is generally a very poor coding practice to reference something by its name. Nothing is stopping someone from creating another object named "Panel" later on, and then which one gets returned from your "Find" function is anyone's guess.

Second, you have a game object that gets returned from AddChild. Just use GetComponent<UILabel>() on it.
Title: Re: Access to object thats been added using NGUITools.AddChild()
Post by: WUTAI on October 24, 2013, 09:48:22 PM
I didn't know AddChild returned a game object. /facepalm

Thanks ;D