FPS Controller fighting with Cursor.LockState

I had a tough time getting the Cursor lock to work as instructed so I made the following modifications to my code. Not sure what caused my issue but this seems to solve it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;

public class DeathHandler : MonoBehaviour
    [SerializeField] GameObject gameOverCanvas;
    FirstPersonController firstPersonController;
    // Start is called before the first frame update
    void Start()
        firstPersonController = GetComponent<FirstPersonController>();

public void HandleDeath()
        firstPersonController.enabled = false;
        Cursor.lockState = CursorLockMode.None;
        Cursor.visible = true;
        gameOverCanvas.SetActive (true);

Well, you didn’t say anything about your issue, except it’s your issue.
If you would explait it, it could help somebody who found your issue in his code too.

For next generations.
Issue is about new input system. Character keeps rotating to follow the mouse during death. Disabling controller solves this issue. There is no need to reenable it after scene reload.

I had to make different Import then OP, it could be different version of StarterAssets.

using StarterAssets;

Inside SceneLoader.cs i have added Cursor unlocking part too, because mouse was still visible after reload.

public void ReloadGame()
        Time.timeScale = 1;
        Cursor.lockState = CursorLockMode.Confined;
        Cursor.visible = false;

Thanks for this! I encountered the same issue. I guess it’s down to a difference in the new Unity first person controller asset.

Privacy & Terms