Add pause menu and fix static data dulpication when loading scenes

This commit is contained in:
BuyMyMojo 2023-03-04 03:57:30 +11:00
parent 0849fcfde7
commit e4706c7a42
11 changed files with 992 additions and 2 deletions

View file

@ -6,8 +6,11 @@ using UnityEngine;
public class GameInput : MonoBehaviour
{
public static GameInput Instance { get; private set; }
public event EventHandler OnInteractAction;
public event EventHandler OnInteractAlteranteAction;
public event EventHandler OnPauseAction;
private PlayerInputActions playerInputActions;
@ -15,11 +18,28 @@ public class GameInput : MonoBehaviour
private void Awake()
{
Instance = this;
playerInputActions = new PlayerInputActions();
playerInputActions.Player.Enable();
playerInputActions.Player.Interact.performed += Interact_performed;
playerInputActions.Player.InteractAlternate.performed += InteractAlternate_performed;
playerInputActions.Player.Pause.performed += Pause_performed;
}
private void OnDestroy()
{
playerInputActions.Player.Interact.performed -= Interact_performed;
playerInputActions.Player.InteractAlternate.performed -= InteractAlternate_performed;
playerInputActions.Player.Pause.performed -= Pause_performed;
playerInputActions.Dispose();
}
private void Pause_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
OnPauseAction?.Invoke(this, EventArgs.Empty);
}
private void InteractAlternate_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)