using UnityEngine; using UnityEngine.UIElements; using UnityEngine.InputSystem; public class MenuControls : MonoBehaviour, SpaceRaceInput.IMenuActions { [SerializeField] UIDocument menuDoc; [SerializeField] UIDocument timingDoc; [SerializeField] ShipControls shipControls; SpaceRaceInput input; bool visible = false; void Start() { if (input == null) { input = new SpaceRaceInput(); input.menu.SetCallbacks(this); } input.menu.Enable(); Hide(); } void Show() { visible = true; UnityEngine.Cursor.lockState = CursorLockMode.None; menuDoc.enabled = true; // take control off the ship timingDoc.enabled = false; shipControls.enabled = false; } void Hide() { visible = false; UnityEngine.Cursor.lockState = CursorLockMode.Locked; menuDoc.enabled = false; // resume control of the ship timingDoc.enabled = true; shipControls.enabled = true; } public void OnToggleMenu(InputAction.CallbackContext ctx) { visible = !visible; // Debug.Log($"Menu {visible}"); if (visible) { Show(); return; } Hide(); return; } }