lcokCursor for ingame menu doesn't work, NEED HELP!!!

I am trying to create a simple in game menu but I just can’t get it to work. Everything looks fine, it doesn’t work and it keeps doing wired stuff (like if I am standing in front of an interactive charactor in my game, the code works!) Otherwise the cursor will not lock. It seems like the cursor is constantly being locked and unlocked somehow. Please help.

var menuSkin : GUISkin;

private var openMenu : boolean = false;

function OnGUI()

{

if(openMenu)

{

	Time.timeScale = 0;

	

	GUI.skin = menuSkin;

	

	GUI.Box(Rect((Screen.width/2)-100,(Screen.height/2)-110,200,220),"");

	

	if(GUI.Button( Rect( (Screen.width/2)-100, (Screen.height/2)-100, 200, 60),"Resume"))

	{

		Screen.lockCursor = true;

		openMenu = false;

	}

	if(GUI.Button( Rect( (Screen.width/2)-100, (Screen.height/2)-30, 200, 60),"Main Menu"))

	{

		openMenu = false;

		OpenLevel("Deadly Nightshade Start Menu");

	}

	if(GUI.Button( Rect( (Screen.width/2)-100, (Screen.height/2)+40, 200, 60),"Quit"))

	{

		Application.Quit();

	}

}

else

	Time.timeScale = 1;

}

function Update()

{

if(!openMenu && Input.GetButtonDown("Q"))

{

	openMenu = true;

	Screen.lockCursor = false;

}

else if(openMenu && Input.GetButtonDown("Q"))

{

	openMenu = false;

	Screen.lockCursor = true;

}

}

function OpenLevel(level:String)

{

//audio.PlayOneShot(beep);

Application.LoadLevel(level);

}

I fixed it. Remember when I said if I am standing in front of an interactive character in my game, the code works. That’s why, I locked the cursor when checking states in my interactive GUI code.