GUI Button problem

    void OnGUI(){

    if(TimerScript.TimerCount > 0f)
    {
            GUI.backgroundColor = new Color(0,0,0,0);
            BackToMain = GUI.Button (new Rect (Width,Height,WidthSize,HeightSize), PauseButtonGUI);

           
            if(BackToMain)
            {
                Debug.Log("TRUE");
            }
            else
            {
                Debug.Log("FALSE");
            }
    }

Why when i press the button, it keeps being true for one frame? it shouldn’t be true until i press again to make it false?

If im not totally wrong, buttons only return true when they are pressed, so if you want it to stay true until you press it again, you should add a bool var. Your if-statement could be like this:

bool boolvar ;

if(BackToMain) && boolvar = true {
boolvar == false ;
Debug.Log(“FALSE”);
}
else if(BackToMain) && boolvar = false {
boolvar == true ;
Debug.Log(“TRUE”);
}

Sorry if it is a bit wrong, I have not programmed for a while. But i hope you get the idea.