Author Topic: UIToggle - What is wrong  (Read 1799 times)

Kafar

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 27
    • View Profile
UIToggle - What is wrong
« on: November 16, 2015, 09:17:26 AM »
Hi,

I created a UIButton and added a UIToggle script.
From another script attached on a camera I need to handle the click button to flash light on/off.
This is the script code portion but when I press the button the compiler not enter in event. Why?
Thanks

public class MenuFixedController : MonoBehaviour
{
   UIToggle myFlashLightButton;

   void Start()
   {
              myFlashLightButton = (UIToggle) GetComponentInChildren<UIToggle>().GetComponent("FlashButton");
              EventDelegate delFlashLight = new EventDelegate (this, "OnFlashLightButtonChange");
         EventDelegate.Set (myFlashLightButton.onChange, delFlashLight);
   }

   void OnFlashLightButtonChange(GameObject go)
   {
      // DO MY STUFF
   }
 }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIToggle - What is wrong
« Reply #1 on: November 18, 2015, 04:01:11 PM »
Many things...
  1. public class MenuFixedController : MonoBehaviour
  2. {
  3.    UIToggle myFlashLightButton;
  4.  
  5.    void Start()
  6.    {
  7.          myFlashLightButton = GetComponentInChildren<UIToggle>();
  8.          EventDelegate.Set (myFlashLightButton.onChange, OnFlashLightButtonChange);
  9.    }
  10.  
  11.    void OnFlashLightButtonChange ()
  12.    {
  13.       // DO MY STUFF
  14.    }
  15.  }