Files
BABA_YAGA/Assets/Scripts/Player Controller/PlayerInteractState.cs
2026-03-26 20:27:19 +07:00

38 lines
1.3 KiB
C#

using UnityEngine;
namespace OnlyScove.Scripts
{
public class PlayerInteractState : PlayerBaseState
{
public PlayerInteractState(PlayerStateMachine stateMachine) : base(stateMachine) {}
public override void Enter()
{
// Lấy vật thể đang được chọn (Index hiện tại)
IInteractable interactable = stateMachine.GetInteractable();
if (interactable != null)
{
Debug.Log($"[Interaction] Interacting with: {interactable.InteractionPrompt}");
interactable.OnInteract(stateMachine);
// Bạn có thể phát animation tương tác ở đây
// stateMachine.Anim.CrossFadeInFixedTime("Interact", 0.1f);
}
// Chuyển về trạng thái di chuyển hoặc đứng yên ngay lập tức
if (stateMachine.Input.MoveInput == Vector2.zero)
{
stateMachine.SwitchState(new PlayerIdleState(stateMachine));
}
else
{
stateMachine.SwitchState(new PlayerMoveState(stateMachine));
}
}
public override void Tick(float deltaTime) { }
public override void PhysicsTick(float fixedDeltaTime) { }
public override void Exit() { }
}
}