Toggle, script order causing issues

Okay so I have a “MainMenu” and a “LevelSelection” GUI

When Selection is open it closes and opens MainMenu, if MainMenu is open it closes, If neither are open then MainMenu Opens

void Update() {

	if (guimain.enabled == true)
	{
		if (Input.GetKeyDown("escape"))
		{
			guimain.enabled = false;
		}
	}

	
	if (guimain.enabled == false)
	{
		if (Input.GetKeyDown("escape"))
		{
			
			if (GUIlevelsel.enabled == true)
			{
				GUIlevelsel.enabled = false;
				guimain.enabled = true;
			}
			
			if (GUIlevelsel.enabled == false)
			{
				guimain.enabled = true;
			}
		}
	}
}

Okay so for some reason… depending on where I place it, it acts differently

if the disable is last then it wont open at all, if the enable is last then it will open but I cannot close it!

How do I code it so it doesn’t do the first then the 2nd if right after, I only want escape click to do 1 thing which is either

The problem you’re having is that you “CAN” make a change to guimain.enabled and then fall through to the next if(checking for false after you just changed it).
Since update is called once per frame, you will want to make a change so during the frame it does either, not one and evaluates the same state in the next statement.

void Update() {

    if (guimain.enabled == true)
    {
        if (Input.GetKeyDown("escape"))
        {
            guimain.enabled = false;
        }
    } 
		else // The case when guimain.enabled == false.
		{
        if (Input.GetKeyDown("escape"))
        {
            if (GUIlevelsel.enabled == true)
            {
                GUIlevelsel.enabled = false;
                guimain.enabled = true;
            }

            if (GUIlevelsel.enabled == false)
            {
                guimain.enabled = true;
            }
        }
		}
}