unity t-flip flop

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