- Home /
              This question was 
             closed Feb 16, 2015 at 06:12 PM by 
             fafase for the following reason: 
             
 
            The question is answered, right answer was accepted
 
               Question by 
               username132323232 · Feb 16, 2015 at 07:05 AM · 
                listener  
              
 
              AddListener to a Toggle.
Hello. I would like to attach a listener to checkbox:
 void Start () 
 {
    GameObject cb1 = (GameObject)Instantiate(cbPrefab);
    Toggle t = cb1.GetComponent<Toggle>();
    t.onValueChanged.AddListener(() => handleCheckbox(value)); **error here**
 }
 
 void handleCheckbox(bool value)
 {
    print("handleCheckbox. value=" + value);
 }
The compile error that I get is:
 error CS1593: Delegate `UnityEngine.Events.UnityAction<bool>' does not take `0' arguments
Could somebody help me to fix this? Thanks!
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by fafase · Feb 16, 2015 at 08:16 AM
      t.onValueChanged.AddListener ( (value) => {   // you are missing this
                  handleCheckbox(value);       // this is just a basic method call within another method
              }   // and this one
       );   // closing the AddListener method parameter
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                