Author Topic: Instantiate Issue  (Read 2036 times)

yanebra

  • Guest
Instantiate Issue
« on: June 01, 2013, 05:25:41 AM »
Hi,

I have a problems here,

I have three UIsprite in the Panel under the UIroot.
Once the sprite has been clicked, I scripted it to instantiate another sprite to replace it,
however, the new generated sprite will be created out of the UIroot in the hierachy.
How can I solve it, to make the new sprite appear under the UIroot?
I have checked in this forum, but I really cannot understand, (a newbie in coding)
Please give a help hand.

Many Thx
Yan

dlewis

  • Guest
Re: Instantiate Issue
« Reply #1 on: June 01, 2013, 07:29:20 AM »
Either set the parent of the new sprite directly (newSprite.transform.parent = theParent) or use the AddChild function in NGUITools (I believe)

yanebra

  • Guest
Re: Instantiate Issue
« Reply #2 on: June 03, 2013, 06:09:11 AM »
Re: dlewis

Thank you very much, by your guide I have tackled it.

for others who may have same question FYR.

var Parent: String;
var theChild: GameObject;

NGUITools.AddChild(GameObject.Find("Parent"), theChild));