Added start button to pause game
This commit is contained in:
parent
5440c56426
commit
543ae0599b
@ -18,12 +18,20 @@ public class AIEntity : Entity
|
|||||||
|
|
||||||
override protected void Update() {
|
override protected void Update() {
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
|
if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop)
|
||||||
|
return;
|
||||||
|
|
||||||
if (currentState.UpdateState() is {} newState)
|
if (currentState.UpdateState() is {} newState)
|
||||||
SwitchState(newState);
|
SwitchState(newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected void FixedUpdate() {
|
override protected void FixedUpdate() {
|
||||||
base.FixedUpdate();
|
base.FixedUpdate();
|
||||||
|
|
||||||
|
if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop)
|
||||||
|
return;
|
||||||
|
|
||||||
if (currentState.FixedUpdateState() is {} newState)
|
if (currentState.FixedUpdateState() is {} newState)
|
||||||
SwitchState(newState);
|
SwitchState(newState);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,8 @@ public class GameFlowManager : MonoBehaviour {
|
|||||||
public enum PauseLevel {
|
public enum PauseLevel {
|
||||||
NotPaused,
|
NotPaused,
|
||||||
PreventActions,
|
PreventActions,
|
||||||
WorldFreeze,
|
NothingMoves,
|
||||||
|
TimeStop,
|
||||||
}
|
}
|
||||||
|
|
||||||
[field: SerializeField]
|
[field: SerializeField]
|
||||||
@ -39,7 +40,7 @@ public class GameFlowManager : MonoBehaviour {
|
|||||||
|
|
||||||
void SetPauseLevel(PauseLevel value) {
|
void SetPauseLevel(PauseLevel value) {
|
||||||
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));
|
public void GameOver() => SwitchState(new DeadFlowState(this));
|
||||||
@ -50,11 +51,17 @@ public class GameFlowManager : MonoBehaviour {
|
|||||||
if (!ctx.WasPressedThisFrame(ref lastStartButton))
|
if (!ctx.WasPressedThisFrame(ref lastStartButton))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (CurrentState is StartFlowState) {
|
switch (CurrentState) {
|
||||||
startPrompt.SetActive(false);
|
case StartFlowState _:
|
||||||
SwitchState(new GameplayFlowState(this));
|
startPrompt.SetActive(false);
|
||||||
} else if (CurrentState is GameplayFlowState) {
|
SwitchState(new GameplayFlowState(this));
|
||||||
SwitchState(new PauseMenuFlowState(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 PauseMenuFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {}
|
||||||
|
|
||||||
public override void EnterState() {
|
public override void EnterState() {
|
||||||
|
base.EnterState();
|
||||||
|
gameFlowManager.SetPauseLevel(PauseLevel.TimeStop);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LeaveState() {
|
||||||
base.EnterState();
|
base.EnterState();
|
||||||
gameFlowManager.SetPauseLevel(PauseLevel.NotPaused);
|
gameFlowManager.SetPauseLevel(PauseLevel.NotPaused);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.WorldFreeze)
|
if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (currentState.UpdateState() is {} newState)
|
if (currentState.UpdateState() is {} newState)
|
||||||
@ -51,7 +51,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate() {
|
void FixedUpdate() {
|
||||||
if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.WorldFreeze)
|
if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (safeZone != null && IsInSafeZone) {
|
if (safeZone != null && IsInSafeZone) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user