Hi there I have problem with Lock Cursor in Unity 3D 5 in C#
Replace " Screen.lockCursor = true; " on " Cursor.lockState = true; " and shows an error " error CS0029: Cannot implicitly convert type bool' to UnityEngine.CursorLockMode’ ". Tell me how to fix the error and how to move the cursor, and that he was in the middle of the screen. Need for the shooter.
The error is telling you that Cursor.lockState is not a bool but an enum of type CursorLockMode. Looking in the unity documentation you can see that CursorLockMode can have 3 values, None, Locked, and Confined. Therefore use the following line
You have to have it in update at this time due to a bug in unity where it loses focus. Hopefully they will fix this someday…Unfortunately currently the only way which is bad for performance is this way from what I can tell. You could detect and create an void OnFocus but that would be OS dependent In other words it would be different if it’s a Mac/Phone/Windows/ect ect. So this is the only practical solution for when you lose focus(basically alt+tab) constantly.