Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Kafar on November 16, 2015, 09:17:26 AM

Title: UIToggle - What is wrong
Post by: Kafar 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
   }
 }
Title: Re: UIToggle - What is wrong
Post by: ArenMook 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.  }