Hi, I made a script so when the canvas and the text are not enabled, the cursor is locked and the script is enabled. However, it just doesn’t work. The cursor is still locked even when the canvas and text is disabled.
public class pauseMenu : MonoBehaviour
{
[SerializeField] Canvas canvas;
[SerializeField] TextMeshProUGUI bean;
[SerializeField] Camera cam;
[SerializeField] GameObject areSure;
private void Start()
{
canvas.enabled = false;
areSure.SetActive(false);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
canvas.enabled = true;
Cursor.lockState = CursorLockMode.None;
GameObject.Find("WeaponHolder").GetComponent<WeaponController>().enabled = false;
}
if (bean.enabled == false && canvas.enabled == false)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = true;
GameObject.Find("WeaponHolder").GetComponent<WeaponController>().enabled = true;
}
}