Hi, I’m new to Unity and I have been trying to get my cursor locked on the screen. I’ve followed a few tutorials and they all basically give me this code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HideCursor : MonoBehaviour
{
void Update()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
}
The code does not work though. The cursor is invisible when on the screen, but I can move the cursor anywhere, even off the screen. Does anyone know the problem? Thanks.,I’m new to Unity and I am trying to lock my cursor, and I followed a few tutorials which all basically gave me this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HideCursor : MonoBehaviour
{
void Update()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
}
However this script is not working, the cursor becomes invisible when on the screen, but it is not locked and I can move it wherever. Does anyone know how to fix this? Thanks!