Author Topic: Access to object thats been added using NGUITools.AddChild()  (Read 1614 times)

WUTAI

  • Guest
Access to object thats been added using NGUITools.AddChild()
« 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Access to object thats been added using NGUITools.AddChild()
« Reply #1 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.

WUTAI

  • Guest
Re: Access to object thats been added using NGUITools.AddChild()
« Reply #2 on: October 24, 2013, 09:48:22 PM »
I didn't know AddChild returned a game object. /facepalm

Thanks ;D