Author Topic: How can i Instantiate a prefab with NGUI ?  (Read 8157 times)

Sahkan

  • Jr. Member
  • **
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 74
    • View Profile
How can i Instantiate a prefab with NGUI ?
« on: June 15, 2014, 10:53:28 AM »
When ever i use this : Instantiate(Prefab);

It instantiates it with a scale about 100 times bigger then it should be, even though it shows scale : 1 just like it was in the original prefab .

How can i make it work with NGUI ?

Caio.Lib

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 26
    • View Profile
Re: How can i Instantiate a prefab with NGUI ?
« Reply #1 on: June 15, 2014, 03:36:50 PM »
Hi,
You can use: NGUITools.AddChild(GameObject parent, GameObject prefab);

BehindTheStone

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 135
    • View Profile
Re: How can i Instantiate a prefab with NGUI ?
« Reply #2 on: June 15, 2014, 05:26:53 PM »
If you happen to use NGUITools.Addchild and want to load your Prefab from your Resources, don't forget that Resources.Load() returns an Object and not a GameObject.
AddChild is an overloaded method:

- AddChild(GameObject, bool)

- AddChild(GameObject, GameObject)

If you want proper behaviour, then just cast your Resources.Load() as a GameObject or just use "as GameObject" after the method like:

  1. NGUITools.AddChild(parent, Resources.Load("path") as GameObject);

Sahkan

  • Jr. Member
  • **
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: How can i Instantiate a prefab with NGUI ?
« Reply #3 on: June 15, 2014, 11:30:33 PM »
Thanks a lot you two, that's works great  :D