A
A
Andrii Programmer2022-03-04 00:16:59
Unity
Andrii Programmer, 2022-03-04 00:16:59

How to unlock cursor in Unity?

I'm making my first game, making a first person shooter, using an FPS contoller, making a menu, but when I lose, the cursor doesn't show up! Tried Cursor.lockState = CursorLockMode.None; Cursor.visible = true; and yes, it only works at start, but I need to make it work before loading the scene, but it doesn’t work like that, please tell me how to do it!

Here is my final version (tried easier, but did not work)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Player : MonoBehaviour
{
    public bool playerdie;
    // Start is called before the first frame update
    void Start()
    {
        playerdie = false;
    }

    // Update is called once per frame
    void Update()
    {
        if(playerdie == true)
        {
            cursor();
        }
    }

    void OnCollisionEnter(Collision shit)
    {
        if (shit.gameObject.tag == "Zombie")
        {

            playerdie = true;
            Invoke("ReloadSceneZero", 2);
        }
    }
    public void cursor()
    {
        Cursor.lockState = CursorLockMode.None;
        Cursor.visible = true;
    }
}


If necessary, I used https://assetstore.unity.com/packages/templates/sy...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question