- Home /
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.
Answer by Kazaskater · Dec 22, 2010 at 08:40 AM
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.
Sorry, i think you misunderstood my question. What my problem is is not the script structure, but the lock cursor function. I cant get the lock cursor function working, and i have no idea why. Anyone that can help me fix this thing?
Answer by Nolirneen · May 05, 2011 at 08:18 AM
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.
the problem is that its automatically built to lock once you click the screen... if you have found a solution by now id love to here it, im having the same issue.
Answer by Aldwoni_legacy · May 05, 2011 at 08:45 AM
Use a Debug.Log in both the if and the else. I expect that he goes through both.
Your answer
Follow this Question
Related Questions
turn off script with a key.. 1 Answer
One Last GUI Question 1 Answer
input from mouse relative to screen dimensions- how to 1 Answer
Unity 3D Screen.lockCursor Problems 2 Answers
Mouse locked in center 1 Answer