Hide Cursor Problems

Hello, so im a noob at this and im having problems, I have this script that I want to hide and lock the cursor on startup, and unlock and show the cursor when I press escape.
But heres the problem, after I press escape to unlock and show, and I press escape to lock and hide the cursor again, it only hides the cursor and doesnt lock it in place, what am I doing wrong?

var showingMouse : boolean;

function Start () {
	showingMouse = false;
	Screen.showCursor = false;
	Screen.lockCursor = true;
}
	





function Update () {
	//if escape is pressed, unlock cursor and show cursor
		if (Input.GetButtonDown("Esc") && showingMouse == false){
			showingMouse = true;
			Screen.showCursor = true;
			Screen.lockCursor = false;
	}	
	
		else if (Input.GetButtonDown("Esc") && showingMouse == true){
			showingMouse = false;
			Screen.showCursor = false;
			Screen.lockCursor = true;
	}
	
}

lock cursor should hide and center the cursor

remember that lock cursor wont work exactly right in the editor, only in the build

try this code to just toggle it

 if (Input.GetButtonDown("Esc"))
{
Screen.lockCursor = !Screen.lockCursor;
}