MountainSide Studios MountainSide Studios - 1 year ago 93
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 Source

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;