Author Topic: Injecting gameobject to ngui hierarchy  (Read 3063 times)

Alex

  • Guest
Injecting gameobject to ngui hierarchy
« on: May 14, 2012, 04:56:09 PM »
Hi,
I made and item from ngui and make a prefab from it. for example:
*Item  <--- Item.cs script attached here
**Button1
**Button2

CMenu.cs is my ngui hierarchy  menu which i want to add the Item to.

When i try to place this 'Item' in my ngui hierarchy , i do this (in my Item.cs):

Transform tmp = CMenu.instance.transform.Find("Camera/Anchor");
f( tmp!=null ){
   transform.parent = tmp;
        transform.localPosition = new Vector3( 10f,10f,0f);
}

when i run the code, the position of the item is change to a huge number and not 10f,10f,0f
how can i fix that?

Thanks


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Injecting gameobject to ngui hierarchy
« Reply #1 on: May 14, 2012, 05:18:32 PM »
I don't see anything wrong with it, considering that you're resetting the local position after parenting the object. Check what other scripts you have on your item and see what they do.

Also, finding objects by name is generally a very bad idea. Use inspector-set references or singletons instead.