Ok: New project, one scene, with one script, slapped on the main camera:
void Start () {
Screen.lockCursor = true;
}
I kick off an exe: nuthin. The cursor is definitely hidden in the game window, but not locked- I can just move the cursor onto another window and lose focus on my game.
I’m almost certain I got this working at some point. Through many trials last year, I found there were several undocumented things that would unlock the cursor (like resolution changes at runtime). But this seems about as simple as it could possibly be. Why oh why does this not work?
Please help.
Thanks!
Orion
I had this issue, i ended up locking in Update and doing a check to see if it’s not locked.
private bool m_LockCursor = true; // enables / disables the mouse cursor
public bool LockCursor
{
get
{
return this.m_LockCursor;
}
set
{
this.m_LockCursor = value;
Screen.lockCursor = value;
}
}
void Update(){
Screen.lockCursor = this.LockCursor;
}
This is c-sharp.
You know what? Your code worked great on Mac OS, and not at all on Windows 7. This may be the problem. Not good.
I added some GUI text to show the state of Screen.lockCursor. On my windows build, it == true the whole time, but the cursor is not actually being locked (just hidden).
Thanks a lot for the help. What platform are you running yours on?
Ha! I think this may be solved: I also had Unreal Ed open on my Windows machine- it seems to have been interfering somehow, preventing cursor locking in my Unity app. Closing it did the trick. Weird!