Files
Knight_Hollow/Assets/Scripts/Player/StateMachine.cs
2025-08-11 21:36:59 +09:00

51 lines
968 B
C#

using UnityEngine;
public class StateMachine
{
private Animator animator;
private IState _state;
private PlayerMove _playerBase;
// private TextMeshProUGUI _textState;
public StateMachine(IState state, PlayerMove playerMove)
{
// 초기 상태 객체 생성
_playerBase = playerMove;;
_state = state;
_state.Enter();
}
public void Update()
{
_state.Update();
var newState = _state.CheckTransition();
if (_state != newState)
{
_state.Exit();
SetTransition(newState);
}
}
public void SetTransition(IState state)
{
// 다음음 상태로 전환
_state = state;
_state.Enter();
}
}
public interface IState
{
void Enter();
void Update();
void Exit();
// 트리거 조건일 경우 다음 상태로 전환
IState CheckTransition();
}