- Home /
Cannot click button because of CursorLockMode.
I cannot click a button whenever i'm on pause mode. When i click the button the cursor will gone again. Any solution to this?
public class LockCursorInGame : MonoBehaviour { // Start is called before the first frame update void Start() { LockCursor(); }
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
UnlockCursor();
}
if (Input.GetMouseButton(0))
{
LockCursor();
}
}
private void LockCursor()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void UnlockCursor()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
Answer by bombombambam · Apr 21, 2020 at 08:03 PM
And why are you surprised? you have it in code.
oh thanks for the reply. I thought nobody would reply to this question. So yeah, any solution to this? Because i want to make sure i can quit the game when i'm on pause mode.
void Start()
{
LockCursor();
}
bool isPaused = false;
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if(!isPaused)
{
UnlockCursor();
isPaused = true;
}
else
{
LockCursor();
isPaused = false;
}
}
}
private void LockCursor()
{
Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
Cursor.visible = false;
}
private void UnlockCursor()
{
Cursor.lockState = CursorLock$$anonymous$$ode.None;
Cursor.visible = true;
}
Your answer
Follow this Question
Related Questions
Cursor appearance change when mouse over a GUI button 2 Answers
Only want to detect button click event 1 Answer
UI Button Doesn't Seems to be Interact with Custom Cursor Image 2 Answers
When enter deathscene cursor disappear 0 Answers
Problem Button Click with Cursor, Cursor attach the gameobject 2 Answers