25 lines
531 B
C#
25 lines
531 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace State
|
|
{
|
|
public class StateMachine : MonoBehaviour
|
|
{
|
|
public event Action<GameState> OnStateChange;
|
|
protected GameState CurrentState;
|
|
|
|
public void ChangeState(GameState newState)
|
|
{
|
|
CurrentState?.OnExit();
|
|
CurrentState = newState;
|
|
CurrentState?.OnEnter(this);
|
|
OnStateChange?.Invoke(CurrentState);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
CurrentState?.Update();
|
|
}
|
|
}
|
|
}
|