Question by
markenzoshukshuk · Mar 07, 2021 at 08:26 AM ·
camera-lookbugs
cursor not locking to the middle of the screen.,First person problem with the camera
Whenever I play the game I'm making, I always have to click first because the cursor is not locked until i click. Here is the code that is attached to my camera:
public Transform player;
public float mousesens = 10;
private float x = 0;
private float y = 0;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
x += -Input.GetAxis("Mouse Y") * mousesens;
y += Input.GetAxis("Mouse X") * mousesens;
x = Mathf.Clamp(x, -90, 90);
transform.localRotation = Quaternion.Euler(x, 0, 0);
player.transform.localRotation= Quaternion.Euler(0, y, 0);
}
Is there anything wrong? my unity version is 2020.2.7f1 and I am using visual studio as my script editor.
thank you very much in advance
Comment