Files
gpd-924-en/AI/Assets/Scripts/FSM/ChaseSystem.cs
T
david fccc1849fe add unity project
add FSM examples
2025-04-09 07:51:22 +02:00

37 lines
964 B
C#

using System;
using UnityEngine;
namespace DefaultNamespace.FSM
{
public class ChaseSystem : MonoBehaviour, IFiniteStateMachine
{
[SerializeField] private IState _defaultState;
[SerializeField] private PlayerController _player;
private IState _currentState = null;
private void Awake()
{
// _currentState = _defaultState; // isn't working, because an interface can't be serialized by the Unity Serializer
_currentState = new IdleState(gameObject, _player, 60.0f);
}
private void Start()
{
_currentState?.Enter(this);
}
private void Update()
{
// if (_currentState == null) return;
_currentState?.Update(this);
}
public void SetState(IState state)
{
_currentState.Exit(this);
_currentState = state;
_currentState.Enter(this);
}
}
}