add unity project
add example for FSM
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user