Screen.lockCursor not working?

Hi, This is a full script of mine :

var Guiscript : MyGui ;

function Update () {

if (Input.GetKeyDown ("escape")){
        if (Guiscript.enabled == true){
        Guiscript.enabled = false;
        Screen.showCursor = false; 
        Screen.lockCursor = true;
        }
        else {
        Guiscript.enabled = true;
        Screen.showCursor = true; 
        Screen.lockCursor = false;
        }
    }
}

I used the Screen.lockCursor function in the script but I cant get the mouse to be locked in the game. I don't think theres any error in this script, is this some kind of bug? I'm using windows btw.

Your making this too complicated. Just make the start function and in there, type in:

Screen.lockCursor = true;

and by default, when you press escape, it will unlock the cursor. I hope thats what you wanted, but I did't really understand your question.

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

That should make the lock cursor work, but I'm facing this problem as well. I want the cursor to lock and unlock like in a fps game when the menu comes up the cursor unlocks.

I'm still looking into it though.

Use a Debug.Log in both the if and the else. I expect that he goes through both.