Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: misterkeeter on May 22, 2014, 09:40:47 PM
-
This following code always creates the prefab at 0,0,0.
I'm not really sure why.
void Start ()
{
GameObject New = Instantiate(instance, transform.localPosition , transform.localRotation)as GameObject;
Vector3 pos = new Vector3 (-50f, -250f, 0f);
New.gameObject.transform.position = pos;
}
Any Help is appreciated.
-
You should not be using Instantiate() with UI elements. UI elements need to be parented properly from the very start. Use NGUITools.AddChild(parent, prefab).
-
Thanks that worked.
Here's my modified code that performed as expected.
void Start () {
GameObject New = NGUITools.AddChild (myUIRoot, instance);
Vector3 pos = new Vector3 (-50f, -250f, 0f);
New.transform.localPosition = pos;
}