toggle bool unity code example
Example 1: unity t-flip flop
private bool onoff = false;
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
onoff = !onoff; // toggles onoff at each click
if (onoff)
{
print("left");
}
else
{
print("right");
}
}
Example 2: bool toggle unity c#
private bool togl;
togl = !togl; //this is what changes the bool the the other state