Screen.lockCursor hasn't been working for me since the update. Why is this, and is there a workaround?
EDIT: Also, got this quote from the docs: "The cursor will automatically be hidden, centered on view and made to never leave the view."
None of that happens. The cursor is not hidden, it's not centered, and it can leave the view. What's going on here?
EDIT 2: After some more playing around, I noticed that it locks correctly if I do not select "Maximize on play"; it seems like the switch from small screen to full screen is messing with it. I can't figure out how to fix it though.
//C#
public static bool lockCursor = true; // Set this to enable/disable the lock.
void Update()
{
if (Screen.lockCursor != lockCursor)
{
if (lockCursor && Input.GetMouseButton(0))
Screen.lockCursor = true;
else if (!lockCursor)
Screen.lockCursor = false;
}
}
In case anyone else has this issue, another culprit can be Playmaker, if you use it. The PlaymakerGUI game object has a bool for “Control Mouse Cursor” and that will override anything you are doing in your code. Had me stumped for days.
This question deserves an update to Unity 5, because it took me forever to find a working one. I kept trying to use Cursor.lockState and finding it unsatisfactory because the cursor would sometimes appear. It is very important to note that modifications to Cursor should be done in OnGUI, not in Update. The following sample code, roughly from the docs, works ONLY SO LONG AS OnGUI is used, NOT Update.