I need some sort of an if statement, which allows me to disable any input and increment score while I'm in the pause menu.
The problem is that I don't really understand this kind of pausing code, I'm "used to" the regular boolean one. So, I show all the code.
First script:
public enum GameState
{
Gameplay,
Paused
}
Second script:
public class GameStateManager
{
private static GameStateManager _instance;
public static GameStateManager Instance
{
get
{
if (_instance == null)
_instance = new GameStateManager();
return _instance;
}
}
public GameState CurrentGameState { get; private set; }
public delegate void GameStateChangeHandler(GameState newGameState);
public event GameStateChangeHandler OnGameStateChanged;
private GameStateManager()
{
}
public void SetState (GameState newGameState)
{
if (newGameState == CurrentGameState)
return;
CurrentGameState = newGameState;
OnGameStateChanged?.Invoke(newGameState);
}
}
Third script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PauseController : MonoBehaviour
{
public void PauseGame()
{
GameState currentGameState = GameStateManager.Instance.CurrentGameState;
GameState newGameState = currentGameState == GameState.Gameplay
? GameState.Paused
: GameState.Gameplay;
GameStateManager.Instance.SetState(newGameState);
}
}
And as of last, here is what I've done in my character movement script:
void Start()
{
GameStateManager.Instance.OnGameStateChanged +=
OnGameStateChanged;
}
private void OnDestroy()
{
GameStateManager.Instance.OnGameStateChanged -= OnGameStateChanged;
}
private void OnGameStateChanged (GameState newGameState)
{
enabled = newGameState == GameState.Gameplay;
}
This is all the code. Where and how am I supposed to write the input and score increment "blocking"? I am so sorry for this being so long and I am grateful if you read all this! :)
EDIT: the missing states, which should be disabled. Score:
if (Input.GetMouseButtonDown(0))
{
if (EventSystem.current.IsPointerOverGameObject())
return;
if (ShootOnClick.onGround == false) // this is for disabling input when the player is colliding with the ground
{
//functions
}
else
{
score++;
scoreText.text = score.ToString();
moneyText.text = money.ToString();
}
}
Input:
void CheckInput()
{
//if first input then ignore
if (firstInput)
{
firstInput = false;
return;
}
if (Input.GetMouseButtonDown(0))
{
ChangeDirection();
}
}