Added GameFlowState change update to kill velocity
This commit is contained in:
parent
e015e467e9
commit
4b96196b69
@ -54,6 +54,7 @@ public class Entity : MonoBehaviour {
|
|||||||
protected virtual void Start() {
|
protected virtual void Start() {
|
||||||
if (direction == Vector3.zero && !(this is VampireEntity))
|
if (direction == Vector3.zero && !(this is VampireEntity))
|
||||||
Debug.LogWarning("Entity had null direction.");
|
Debug.LogWarning("Entity had null direction.");
|
||||||
|
gameFlowManager.stateChanged += OnGameFlowStateChanged;
|
||||||
|
|
||||||
attackTimer = attackCooldown;
|
attackTimer = attackCooldown;
|
||||||
initialHealth = Health;
|
initialHealth = Health;
|
||||||
@ -66,6 +67,8 @@ public class Entity : MonoBehaviour {
|
|||||||
|
|
||||||
protected virtual void FixedUpdate() {}
|
protected virtual void FixedUpdate() {}
|
||||||
|
|
||||||
|
protected void OnDestroy() => gameFlowManager.stateChanged -= OnGameFlowStateChanged;
|
||||||
|
|
||||||
protected virtual void Attack() {
|
protected virtual void Attack() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -156,4 +159,9 @@ public class Entity : MonoBehaviour {
|
|||||||
public void DisableHalo() {
|
public void DisableHalo() {
|
||||||
halo.SetActive(false);
|
halo.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnGameFlowStateChanged(BaseState newState) {
|
||||||
|
if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.NothingMoves)
|
||||||
|
rb.velocity = Vector2.zero;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
|
using System;
|
||||||
using NaughtyAttributes;
|
using NaughtyAttributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
@ -37,6 +38,8 @@ public class GameFlowManager : MonoBehaviour {
|
|||||||
[field: SerializeField] TMP_Text startTxt;
|
[field: SerializeField] TMP_Text startTxt;
|
||||||
[field: SerializeField] TMP_Text endTxt;
|
[field: SerializeField] TMP_Text endTxt;
|
||||||
|
|
||||||
|
public event Action<BaseState> stateChanged;
|
||||||
|
|
||||||
#region Unity Messages
|
#region Unity Messages
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
@ -129,9 +132,10 @@ public class GameFlowManager : MonoBehaviour {
|
|||||||
CurrentState.LeaveState();
|
CurrentState.LeaveState();
|
||||||
CurrentState = newState;
|
CurrentState = newState;
|
||||||
newState.EnterState();
|
newState.EnterState();
|
||||||
|
stateChanged?.Invoke(newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class GameFlowState : BaseState {
|
public abstract class GameFlowState : BaseState {
|
||||||
readonly protected GameFlowManager gameFlowManager;
|
readonly protected GameFlowManager gameFlowManager;
|
||||||
|
|
||||||
protected GameFlowState(GameFlowManager gameFlowManager) {
|
protected GameFlowState(GameFlowManager gameFlowManager) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user