Added GameFlowState change update to kill velocity

This commit is contained in:
Jason Durand 01 2022-04-03 15:19:06 -04:00
parent e015e467e9
commit 4b96196b69
2 changed files with 13 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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<BaseState> 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) {