MountainSide Studios MountainSide Studios - 3 months ago 21
C# Question

Changing result doing the same thing

How would I go about making it so that if I pressed S it would set a boolean to true and then if I pressed it again it would set that boolean to false in a relatively short few lines of code.

Answer

Use the ! symbol to flip the boolean variable when the S key is pressed.

bool someBool = false;
void Update()
{
    if (Input.GetKeyDown(KeyCode.S))
    {
        someBool = !someBool;
    }
}