Author Topic: How can I set prefab button target?  (Read 2864 times)

imnemone

  • Guest
How can I set prefab button target?
« on: March 28, 2013, 11:00:21 PM »
Hello.

I want to make shop window as a prefab.
Because, It doesn't need to loaded at start.
I want to create the "shop window" when user click the ShopButton in the main screen.

If I make shop window as prefab, I lost button's target it is GUIManager gameObject.

There is many buttons in the show window.

I have no idea.

I need some advice please.

Thx.



Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: How can I set prefab button target?
« Reply #1 on: March 29, 2013, 09:08:27 AM »
If you make it as a prefab and want to load it dynamically, you have to save it in a Resources folder (or subfolder to that) and use Resources.Load to load the prefab by name. Then you can instantiate it to make a copy of the prefab and there you go.

imnemone

  • Guest
Re: How can I set prefab button target?
« Reply #2 on: March 31, 2013, 09:25:16 PM »
Yes, I did already.

But, When I instantiate the prefab , all buttons target lost its target.

So, I manually assign target to every button in script.

Is there other method ?

Assigning target of buttons is  put me to trouble.

Thx.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How can I set prefab button target?
« Reply #3 on: March 31, 2013, 09:50:33 PM »
Anything outside the prefab is effectively unknown when you instantiate the prefab. So if your button has public references to something outside the prefab, you will lose this reference. That's just how Unity works.