- Home /
Cursor locking and visibility.
I want to have locked and invisible cursor in the game and in the menu visible and unlocked. I use: Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; but it didn't work properly. Sometimes it's work, sometimes not. I don't call it every frame, but even when I call it don't work. It is in my code in separated method in my own namespace and I call it when I turn on/off the menu canvas (I tried call it every frame but it don't work). By the way it's looks like that:
if (tribe == game) {
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
Time.timeScale = 1;
} else if (tribe == menu) {
Cursor.lockState = CursorLockMode.Confined;
Cursor.visible = true;
Time.timeScale = 0;
} else if (tribe == inventory) {
Cursor.lockState = CursorLockMode.Confined;
Cursor.visible = true;
Time.timeScale = 0;
}
(I don't know how to use that answer editor properly, sorry :C )
Variables like game or menu are declared in the class and if statemenst works properly because I checked it, but Cursor.lockState and Cursor.visible are doing nothing (or my editor blocks it or something.
If it's problem without solution I'm going to make new cursor (or image) which I will move and when in game it will have alpha set to 0. Sorry for my English, it's to early today to write well. :(