Skip to content

Commit

Permalink
fix: prevent error or no previous state
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisonHough committed Jun 10, 2024
1 parent ac0d942 commit 819e7c5
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class StateMachine : MonoBehaviour

protected Action<StateType, StateType> StateChanged;
private StateType currentState;

protected void Initialize(List<State> states)
{
foreach (var state in states)
Expand All @@ -34,7 +34,7 @@ public void SetState(StateType stateType)
SetState(stateTypeMap[stateType].NextState);
return;
}

previousStates.Push(previousState);
}

Expand All @@ -56,7 +56,11 @@ public void GoToPreviousState()
var previousState = currentState;

DeactivateState(stateTypeMap[previousState]);


if (previousStates.Count == 0)
{
return;
}
currentState = previousStates.Pop();
if (currentState != StateType.None)
{
Expand All @@ -70,7 +74,7 @@ private void ActivateState(State state)
state.gameObject.SetActive(true);
state.ActivateState();
}

private void DeactivateState(State state)
{
state.gameObject.SetActive(false);
Expand Down

0 comments on commit 819e7c5

Please sign in to comment.