Check out example codes for "toggle unity c#". It will help you in understanding the concepts better.

Code Example 1

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
        }

Learn ReactJs, React Native from akashmittal.com