Files
gpd-925-en/AI/Assets/Scripts/FSM/ChaseStateMachine.cs
T
david 10f61fd5d9 Added AI Unity project
Added FSM examples
2026-04-20 18:37:00 +02:00

68 lines
1.8 KiB
C#

using System;
using UnityEngine;
namespace AI.FSM
{
public class ChaseStateMachine : MonoBehaviour, IFiniteStateMachine
{
[SerializeField] private Transform player;
private IState _currentState;
// private IdleState _idleState;
// private PlayerDetectedState _playerDetectedState;
// // ...
// private void Awake()
// {
// _idleState = new IdleState();
// _playerDetectedState = new PlayerDetectedState();
// // ...
// }
private void OnEnable()
{
ChangeState(new IdleState(gameObject, player, 30.0f));
}
private void OnDisable()
{
ChangeState(null);
}
public void Update()
{
_currentState?.Update(this);
}
public void ChangeState(IState state)
{
_currentState?.Exit(this);
_currentState = state;
_currentState?.Enter(this);
}
// public void ChangeState(States state)
// {
// _currentState?.Exit(this);
//
// switch (state)
// {
// case States.Idle:
// _currentState = _idleState;
// break;
// case States.PlayerDetected:
// _currentState = _playerDetectedState;
// break;
// case States.PlayerInRange:
// break;
// case States.PlayerOutOfRange:
// break;
// default:
// throw new ArgumentOutOfRangeException(nameof(state), state, null);
// }
//
// _currentState?.Enter(this);
// }
}
}