toggle unity c#

C#
private bool togl;//this is either true or false

        if (Input.GetKey(KeyCode.A)) //can have whatever statment you want here
        {							 
            togl = !togl; //this is what changes the bool
        }
Source

Also in C#: