#if anyone see's this and feels like
1 messages · Page 1 of 1 (latest)
his two scripts
imma make a little test scene..
things that originally had their own cursor logic
- character controller
- pause menu
so my new setup would still have the
- character controller
- pause menu
but both of these scripts would access and change the cursor state
with: - MasterMouse / CursorController or w/e u'd want to call it
using UnityEngine;
public class CursorManager : MonoBehaviour
{
public static CursorManager Instance { get; private set; }
void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
}
public void SetCursor(bool isLocked)
{
Cursor.lockState = isLocked ? CursorLockMode.Locked : CursorLockMode.None;
Cursor.visible = !isLocked;
}
}
``` something like this would be a CursorManager singleton (only 1 would ever exist at a time)...
CursorManager.Instance.SetCursor(true); // Lock and hide cursor
CursorManager.Instance.SetCursor(false); // Unlock and show cursor ```
then any script could call it like ^
that way when u pause u can call the function to unlock the cursor..
that way teh player controller has nothign to do with it..
if the code says the game is paused and the pause menu is open the CursorManager unlocks the cursor.. simple as that...
that way 4 or 5 scripts aren't all trying to change it around..
[Header("DEBUG VALUES")]
public float mouseX;
public float mouseY;
void Update()
{
var getMousePosition = Input.mousePosition;
mouseX = getMousePosition.x;
mouseY = getMousePosition.y;
}``` first step i always take is to debug the mouse position (good to know what values ur actually getting)