Author Topic: trying to make a grid of widgets  (Read 2100 times)

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
trying to make a grid of widgets
« 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!

yeagerj

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: trying to make a grid of widgets
« Reply #1 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: trying to make a grid of widgets
« Reply #2 on: June 14, 2013, 05:09:28 PM »
Right. Never use Instantiate.