Unity
- 9 ответов
- 0 вопросов
3
Вклад в тег
public class StateMachine
{
public void Tick() {}
public void SetState(IState state) {}
}
public interface IState
{
void OnEnter();
void Tick();
void OnExit();
}
fsm = new FSM.StateMachine();
// What states
var wait = new Waiting(this);
var move = new Moving(this, 5f);
var attack = new Attacking(this, Player.Instance);
// Transitions
fsm.AddTransition(wait, move, () => isTargetInRange);
fsm.AddTransition(move, wait, () => !isTargetInRange);
fsm.AddTransition(attack, wait, () => attack.IsComplete());
fsm.SetState(wait);