What is supposed to happen :
Mouse cursor disappears while game is in play mode, reappears after pressing esc and toggling pause menu. While in pause menu, mouse cursor should remain active.
What happens:
Mouse cursor visibility does toggle, but not in correlation with pause menu/play mode. And while in pause menu, cursor does still disappear after clicking.
Note, this is in editor testing, not a build.
Here is my cursor lock state script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace S3
{
public class GameManagerToggleCursor : MonoBehaviour
{
GameManagerMaster gameManagerMaster;
bool isCursorLocked = false;
private void OnEnable()
{
SetInitialRefernces();
gameManagerMaster = GetComponent<GameManagerMaster>();
gameManagerMaster.MenuToggleEvent += ToggleCursorState;
gameManagerMaster.InventoryUIToggleEvent += ToggleCursorState;
}
private void OnDisable()
{
gameManagerMaster.MenuToggleEvent -= ToggleCursorState;
gameManagerMaster.InventoryUIToggleEvent -= ToggleCursorState;
}
private void Update()
{
CheckIfCursorShouldBeLocked();
}
void SetInitialRefernces()
{
gameManagerMaster = GetComponent<GameManagerMaster>();
}
void ToggleCursorState()
{
isCursorLocked = !isCursorLocked;
}
void CheckIfCursorShouldBeLocked()
{
if (isCursorLocked)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
else
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = false;
}
}
}
}
Few things I have tried:
I thought the cursor behavior was tied to the standard asset character controller. I made an independent controller, but I guess the behavior is native to the editor because that made no difference.
I thought there might be a conflict between cursor.lockstate stuff happening in the camera control and the GameManagerToggleCursor (the above script), so I commented out all cursor.lockstate code in the camera control. No change.