From 4b96196b692d1827ec1a8e8eadf71977e5ec1da1 Mon Sep 17 00:00:00 2001 From: Jason Durand 01 Date: Sun, 3 Apr 2022 15:19:06 -0400 Subject: [PATCH] Added GameFlowState change update to kill velocity --- Assets/Scripts/Entity.cs | 8 ++++++++ Assets/Scripts/GameFlowManager.cs | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index 8c24ae3..f0c2422 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -54,6 +54,7 @@ public class Entity : MonoBehaviour { protected virtual void Start() { if (direction == Vector3.zero && !(this is VampireEntity)) Debug.LogWarning("Entity had null direction."); + gameFlowManager.stateChanged += OnGameFlowStateChanged; attackTimer = attackCooldown; initialHealth = Health; @@ -66,6 +67,8 @@ public class Entity : MonoBehaviour { protected virtual void FixedUpdate() {} + protected void OnDestroy() => gameFlowManager.stateChanged -= OnGameFlowStateChanged; + protected virtual void Attack() { } @@ -156,4 +159,9 @@ public class Entity : MonoBehaviour { public void DisableHalo() { halo.SetActive(false); } + + void OnGameFlowStateChanged(BaseState newState) { + if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.NothingMoves) + rb.velocity = Vector2.zero; + } } diff --git a/Assets/Scripts/GameFlowManager.cs b/Assets/Scripts/GameFlowManager.cs index cfdf213..82557a6 100644 --- a/Assets/Scripts/GameFlowManager.cs +++ b/Assets/Scripts/GameFlowManager.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using NaughtyAttributes; using UnityEngine; using UnityEngine.InputSystem; @@ -37,6 +38,8 @@ public class GameFlowManager : MonoBehaviour { [field: SerializeField] TMP_Text startTxt; [field: SerializeField] TMP_Text endTxt; + public event Action stateChanged; + #region Unity Messages void Awake() { @@ -129,9 +132,10 @@ public class GameFlowManager : MonoBehaviour { CurrentState.LeaveState(); CurrentState = newState; newState.EnterState(); + stateChanged?.Invoke(newState); } - abstract class GameFlowState : BaseState { + public abstract class GameFlowState : BaseState { readonly protected GameFlowManager gameFlowManager; protected GameFlowState(GameFlowManager gameFlowManager) {