Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: pretender on June 14, 2013, 07:54:47 AM

Title: trying to make a grid of widgets
Post by: pretender on June 14, 2013, 07:54:47 AM
hi!

i made a prefab with one sliced sprite and few labels. position and rotation is at zero while scale is at 1,1,1
i instantiate prefab and made it child of a panel but scale goes to 360,360,360 and position goes to some weird number like 100800,56000,0

scales leading to widgets are all 1,1,1 except the root.

root
 -camera
  -anchor
    -panel
     -widget

when i place the widget in the editor i get correct position and scale, doing it from the code it messes everything up.
here is the code i am using:

  1. e = GameObject.Instantiate(element,new Vector3(0f + 40 * x_index,0f + 40 * y_index, 0f),Quaternion.identity) as GameObject;
  2.                                                 e.transform.parent = Panel.transform;

any help appreciated!
Title: Re: trying to make a grid of widgets
Post by: yeagerj on June 14, 2013, 08:38:04 AM
I think you need to use NGUITools.AddChild to do the instantiation instead. Then reposition the instantiated GameObject as needed afterward.
Title: Re: trying to make a grid of widgets
Post by: ArenMook on June 14, 2013, 05:09:28 PM
Right. Never use Instantiate.