Files
gpd-924/AI/Assets/Scripts/FSM/ChaseSystem.cs
T
david 19a08085fe add unity project
add example for FSM
2025-04-08 13:03:11 +02:00

35 lines
804 B
C#

using System;
using UnityEngine;
namespace DefaultNamespace.FSM
{
public class ChaseSystem : MonoBehaviour, IFiniteStateMachine
{
[SerializeField] private PlayerController _playerController;
private IState _currentState = null;
private void OnEnable()
{
_currentState = new IdleState(gameObject, _playerController, 60.0f);
}
private void OnDisable()
{
_currentState = null;
}
public void Update()
{
if (_currentState == null) return;
_currentState.Update(this);
}
public void SetState(IState state)
{
_currentState.Exit(this);
_currentState = state;
_currentState.Enter(this);
}
}
}