Question by
Akuma-no-Tsubasa · Jun 08, 2017 at 07:04 AM ·
uibuttonunity5
Unity Button to switch Bool
Hello,
I was just following this tutorial: http://catlikecoding.com/unity/tutorials/clock/ It's very helpful but I wanted to add one last step. There is a bool called "analog" and I would like to add a simple unity ui button and when I click it, it activates/deactivates the analog bool.
Thanks for your help !
Comment
Answer by kornstar83 · Jun 08, 2017 at 08:48 AM
you first create a public function that can be called by the UI button, and inside the function you have it toggle the bool.
public void ToggleAnalog(){
analog = !analog;
}
the line,
analog = !analog;
will change the boolean value to the opposite of what it is when the function is called.
Then you just have your button call the public function you just created.
Your answer
![](https://koobas.hobune.stream/wayback/20220612123741im_/https://answers.unity.com/themes/thub/images/avi.jpg)