Check out example codes for "unity t-flip flop". It will help you in understanding the concepts better.

Code Example 1

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");
            }
        }

Learn ReactJs, React Native from akashmittal.com