I just ran into this myself. What's happening is that it's calling your method with a value of 0 when it initializes. This is what I did to resolve this:I think it's not the case.
1. add an int parameter to the callback method. Add this to the beginning of the method: if the value is 0, just return (i.e. ignore it).
2. in the inspector, the int parameter will need to be provided. Drag your UIToggle to it, then select "value" from the property list
Here is my current callback function:There's your state. Don't flip any values. Use the provided state value.
bool myState = UIToggle.current.value;
musicOn = !musicOn; //the booleanThis is backwards and is not needed:
musicButton.value = musicOnYour code should be just one line:
I just said don't flip any values, and you're still flipping the value:This is backwards and is not needed:Your code should be just one line:It works. But I am not quite really understand how it works. Is it when I read the current.value in the callback function, current.value will flip itself?
bgSource.mute = !UIToggle.current.value;