Author Topic: UIButtonMessage used to turn on/off other GameObjects?  (Read 1861 times)

SuperTalesNat

  • Guest
UIButtonMessage used to turn on/off other GameObjects?
« on: April 12, 2013, 01:35:15 PM »
So i'm trying to get my head around this, and could use a little help.

I have Button-A that when pressed, should turn on/off (based on the function provided) another GameObject. I thought this could be done with UIButtonMessage assigned to Button-A, with GameObject-01 in the target slot, and then set Button-A's Function Name to 'SetActive(true)', but this doesnt work because it looks like UIButtonMessage doesn't allow variables to pass along with the function.

What is the proper way to do this? I know i could have a script attached to GameObject-01 that then has functions in it for on/off, and just call that function from UIButtonMessage, but i'm hoping that this simple functionality doesn't require the resulting target to have ANY scripts on them for turning on/off.

Is this possible? Is there a simple way to do this, with, without UIButtonMessage? Or do i need to create a script and attach it to any target object to turn it on/off?

Nathaniel Hunter
SuperTales

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIButtonMessage used to turn on/off other GameObjects?
« Reply #1 on: April 12, 2013, 01:53:19 PM »
Call your own function if you need to use sendmessage.

  1. void MySendMessageActivator()
  2. {
  3. gameObject.SetActive(true);
  4. }

Consider using a more centralized handler object that you can call through, instead of calling sendmessages here and there - it's just a recipe for a headache further down the line. (I speak of experience on just this point).

SuperTalesNat

  • Guest
Re: UIButtonMessage used to turn on/off other GameObjects?
« Reply #2 on: April 12, 2013, 02:11:01 PM »
Thanks Nicki,

Normally it would be handled through more of a MODE script, but this UI is dead simple, and more utility than game.

UIButtonActivate, not sure how i missed that one. Does pretty much what i need it to.

Another, albeit an additional 3rd party script, is here for those interested (allows lists of objects to turn on/off), from another user here, Jeldrez: http://pastebin.com/xrznwM81

Nathaniel Hunter
SuperTales