Lock Cursor problem in Unity 3D 5.

Lock Cursor problem in Unity 3D 5.

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.

Respond fast please !!!

Cheers !!!

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

Cursor.lockState = CursorLockMode.Locked;
using UnityEngine;
using System.Collections;

public class HideLockCursorA : MonoBehaviour
{
void Start ()
  {
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
  }
                  void Update ()
            {
                    Cursor.lockState = CursorLockMode.Locked;
                    Cursor.visible = false;
            }
}

Here is what I did for my lock cursor script

function Start ()
    {
    Screen.lockCursor = true;
    UnityEngine.Cursor.visable = false;
    }

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 :frowning: 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.

void Update()
	{
		if (Cursor.lockState != CursorLockMode.Locked)
		{
			Cursor.lockState = CursorLockMode.Locked;
			Cursor.visible = false;
		}
	}

Well, the script that I used was this:

void Update()
{
        //Mouse lock and confine
        Cursor.visible = false;
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.lockState = CursorLockMode.Confined;

//and to unlock it is this:
        Cursor.lockState = CursorLockMode.None;
        Cursor.visible = true;
}

I hope this helps!