Author Topic: UIToggle onChange problem  (Read 8615 times)

tra

  • Guest
UIToggle onChange problem
« on: October 25, 2013, 11:20:20 PM »
In the older versions I was able to add onChange functions to UICheckbox with code like this:
  1. [...]
  2. public UICheckbox check;
  3.  
  4. void Start ()
  5. {
  6.         check.onStateChange += OnCheckChange;
  7. }
  8.  
  9. void OnCheckChange (bool isOn)
  10. {
  11.         Debug.Log("Checkbox state = "+isOn);
  12. }
  13. [...]
  14.  

Now in 3.0.2 version with UIToggle I was trying something like this:

  1. [...]
  2. public UIToggle toggle;
  3.  
  4. void Start ()
  5. {
  6.         check.onChange += OnToggleChange;
  7. }
  8.  
  9. void OnToggleChange (bool isOn)
  10. {
  11.         Debug.Log("Toggle state = "+isOn);
  12. }
  13. [...]
  14.  

But error like this appears:

Quote
error CS0019: Operator `+=' cannot be applied to operands of type `System.Collections.Generic.List<EventDelegate>' and `method group'

I know there is a visual way of doing this in inspector but i prefer to code ;)
How to code this in new version of NGUI?

bkevelham

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 11
    • View Profile
    • Personal Website
Re: UIToggle onChange problem
« Reply #1 on: October 26, 2013, 04:37:41 AM »
You by now will have to use a

  1. EventDelegate.Add(check.onChange, OnToggleChange);

And your OnToggleChange should not have a boolean argument, but retrieve the value inside its body. You might want to have a look at the migration video that was created: http://www.youtube.com/watch?v=uNSZsMnhS1o