- Home /
Instantiate always at the same position (0,0,0)
I am new to unity and NGUI.
when I instantiate a sprite, whatever I set the position ,it is always appearing at the (0,0,0). Always in the middle of the screen.
void OnClick ()
{
Instantiate (sprite, this.transform.localPosition, Quaternion.identity);
}
this is the code I attach to a NGUI UIButton.
Does this has anything to do with the NGUI? I use UI Root. It's at (0,0,0) and when the sprite is instantiated, it is UI Root's child.
Answer by trololo · Mar 25, 2014 at 11:11 AM
With NGUI, you would prefer to use the NGUITools.AddChild() function to instantiate a new GameObject/prefab. So if you have a GameObject at any specific location (where you want to locate your sprite), do this:
NGUITools.AddChild(gameObjAtLocation, yourPrefab)
Your answer
Follow this Question
Related Questions
NGUI Texture front of Sprite 0 Answers
Why does transform.Rotate not move the sprite and BoxCollider2D together? 1 Answer
NGUI Sprite not visible in 3d when added by code 2 Answers
Problem with Line Renderer 1 Answer
Instantiate a GameObject at a position specific to an element that was found in a text 1 Answer