- Home /
Question by
Rachens · Apr 27, 2019 at 02:43 PM ·
cursorlockcursor
Cursor.lockState not doing anything
I'm trying to lock the cursor when the player presses the return button. I've set up said button in the editor but when i press it nothing happens.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class GameManagerUI : MonoBehaviour
{
public GameObject pauseUI;
public GameObject inventoryUI;
public bool pauseActive = false;
public bool inventoryActive = false;
void Start()
{
pauseUI.SetActive(false);
inventoryUI.SetActive(false);
}
void Update()
{
if (Input.GetKeyDown("e"))
{
inventoryUI.SetActive(!inventoryUI.activeSelf);
if (inventoryUI.activeSelf)
{
inventoryActive = true;
}
else
{
inventoryActive = false;
}
}
if (Input.GetKeyDown("escape"))
{
Toggle();
}
}
public void Resume()
{
Toggle();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
public void Toggle()
{
pauseUI.SetActive(!pauseUI.activeSelf);
if (pauseUI.activeSelf)
{
Time.timeScale = 0f;
pauseActive = true;
}
else
{
Time.timeScale = 1f;
pauseActive = false;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612200317im_/https://answers.unity.com/themes/thub/images/avi.jpg)