diff --git a/Assets/Scripts/AIEntity.cs b/Assets/Scripts/AIEntity.cs index 0c4080a..04eca61 100644 --- a/Assets/Scripts/AIEntity.cs +++ b/Assets/Scripts/AIEntity.cs @@ -18,12 +18,20 @@ public class AIEntity : Entity override protected void Update() { base.Update(); + + if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop) + return; + if (currentState.UpdateState() is {} newState) SwitchState(newState); } override protected void FixedUpdate() { base.FixedUpdate(); + + if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop) + return; + if (currentState.FixedUpdateState() is {} newState) SwitchState(newState); } diff --git a/Assets/Scripts/GameFlowManager.cs b/Assets/Scripts/GameFlowManager.cs index 4f6ed1f..9c342c9 100644 --- a/Assets/Scripts/GameFlowManager.cs +++ b/Assets/Scripts/GameFlowManager.cs @@ -11,7 +11,8 @@ public class GameFlowManager : MonoBehaviour { public enum PauseLevel { NotPaused, PreventActions, - WorldFreeze, + NothingMoves, + TimeStop, } [field: SerializeField] @@ -39,7 +40,7 @@ public class GameFlowManager : MonoBehaviour { void SetPauseLevel(PauseLevel value) { pauseLevel = value; - Time.timeScale = value >= PauseLevel.WorldFreeze ? 0f : 1f; + Time.timeScale = value >= PauseLevel.TimeStop ? 0f : 1f; } public void GameOver() => SwitchState(new DeadFlowState(this)); @@ -50,11 +51,17 @@ public class GameFlowManager : MonoBehaviour { if (!ctx.WasPressedThisFrame(ref lastStartButton)) return; - if (CurrentState is StartFlowState) { - startPrompt.SetActive(false); - SwitchState(new GameplayFlowState(this)); - } else if (CurrentState is GameplayFlowState) { - SwitchState(new PauseMenuFlowState(this)); + switch (CurrentState) { + case StartFlowState _: + startPrompt.SetActive(false); + SwitchState(new GameplayFlowState(this)); + break; + case GameplayFlowState _: + SwitchState(new PauseMenuFlowState(this)); + break; + case PauseMenuFlowState _: + SwitchState(new GameplayFlowState(this)); + break; } } @@ -119,6 +126,11 @@ public class GameFlowManager : MonoBehaviour { public PauseMenuFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {} public override void EnterState() { + base.EnterState(); + gameFlowManager.SetPauseLevel(PauseLevel.TimeStop); + } + + public override void LeaveState() { base.EnterState(); gameFlowManager.SetPauseLevel(PauseLevel.NotPaused); } diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index c6d91cf..96078e7 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -43,7 +43,7 @@ public class PlayerMovement : MonoBehaviour { } void Update() { - if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.WorldFreeze) + if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop) return; if (currentState.UpdateState() is {} newState) @@ -51,7 +51,7 @@ public class PlayerMovement : MonoBehaviour { } void FixedUpdate() { - if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.WorldFreeze) + if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop) return; if (safeZone != null && IsInSafeZone) {