35 lines
927 B
C#
35 lines
927 B
C#
using UnityEngine;
|
|
using System; // ⭐ Action 사용을 위해 필요
|
|
|
|
public class TrainingDummy : MonoBehaviour, IDamageable
|
|
{
|
|
[Header("더미 설정")]
|
|
[SerializeField] private float maxHP = 9999f;
|
|
private float _currentHP;
|
|
|
|
private Animator _animator;
|
|
|
|
// ⭐ UI가 이 신호를 듣고 게이지를 줄입니다.
|
|
public event Action<float, float> OnHealthChanged;
|
|
|
|
private void Start()
|
|
{
|
|
_currentHP = maxHP;
|
|
_animator = GetComponent<Animator>();
|
|
}
|
|
|
|
public void TakeDamage(float amount)
|
|
{
|
|
_currentHP -= amount;
|
|
|
|
// ⭐ UI에 현재 체력과 최대 체력 정보를 보냅니다.
|
|
OnHealthChanged?.Invoke(_currentHP, maxHP);
|
|
|
|
Debug.Log($"<color=red>[더미]</color> 피격! 데미지: {amount} | 남은 체력: {_currentHP}");
|
|
|
|
if (_animator != null)
|
|
{
|
|
_animator.Play("Hit", 0, 0f);
|
|
}
|
|
}
|
|
} |