- Home /
How to change a bool value in game?
Hello all.
I'm trying to sharpen up my C# coding and thought it best to start at the bottom, again. I've been following the tutorials on this site - http://catlikecoding.com/unity/tutorials/clock/
I need a little bit of advice on the matter tho.
In the clockanimation.cs script there is a bool value to toggle the clock analog/digital.
How can I change that value to true/false in game using a button.
I have already added an "exit" button to the game to terminate the program but are having issues implenting the analog true/false button. I have a button script attached to an empty game object in the scene to handle all the button I want to add.
Any advice or help would be of great value.
Thank you in advance.
PS: sorry, using my phone to post this question, not near my pc or have my code handy. Also if I don't make any sense, just curse me. ;)
Answer by nbg_yalta · Jan 11, 2014 at 04:13 PM
If you are talkin about how to toogle bool value via GUI.Button here is the way:
bool myBool;
if(GUI.Button(Rect))
{
myBool = !myBool;
}
Thank you very much. It worked better than I thought. Although I had to add the script to my clockAnimator script using OnGUI, adding it above my Update function. Can I call that bool from my buttons script using GetComponent? I didn't want to clutter my clockAnimator script with button values, but its working and I'm happy. So thanks once again. ;)
Your answer
