EerieVillage/Assets/Scripts/Mechanics/PlayerStateTimer.cs

42 lines
1.4 KiB
C#
Raw Normal View History

using UnityEngine;
namespace Platformer.Mechanics
{
/// <summary>
/// 마지막 공격 시점 추적 + idle⇄combatidle 전환 발동.
/// SOT: 캐릭터_리소스_규칙_v1.md §3.1.1 idle⇄combatidle 5초 타이머
/// 카드·특성 효과로 combatIdleDuration 조정 가능 (P13-1 공용 모듈 인터페이스).
/// BT12-Dev: ISkillRuntime 향후 통합 시 combatIdleDuration 카드 효과 보정 영역 예약.
/// </summary>
[RequireComponent(typeof(PlayerController))]
[RequireComponent(typeof(Animator))]
public class PlayerStateTimer : MonoBehaviour
{
[Tooltip("마지막 공격 후 combatidle 유지 시간(초). 카드·특성으로 증감 가능.")]
public float combatIdleDuration = 5f;
Animator animator;
float lastAttackTime = -100f; // 초기값: 게임 시작 시 idle 상태
void Awake()
{
animator = GetComponent<Animator>();
}
/// <summary>
/// PlayerAttack.Execute 또는 PlayerAttackTicker가 공격 발화 시 호출.
/// 외부 API로 노출하여 결합 최소화.
/// </summary>
public void NotifyAttackFired()
{
lastAttackTime = Time.time;
}
void Update()
{
bool inCombat = (Time.time - lastAttackTime) < combatIdleDuration;
animator.SetBool("combatidle", inCombat);
}
}
}