Can I 'invert' a bool?

boolean, c#

Solution

You can get rid of your if/else statements by negating the bool's value:

ruleScreenActive = !ruleScreenActive;

Problem

I have some checks to see if a screen is active. The code looks like this: ``` if (GUI.Button(new Rect(Screen.width / 2 - 10, 50, 50, 30), "Rules")) //Creates a button { if (ruleScreenActive == true) //check if the screen is already active ruleScreenActive = false; //handle according to that else ruleScreenActive = true; } ``` Is there any way to - whenever I click the button - invert the value of `ruleScreenActive`? (This is C# in Unity3D)

Original source