HPbarzissou
This commit is contained in:
@@ -7,8 +7,10 @@ public class EnemyHealth : MonoBehaviour, IDamageable
|
||||
[SerializeField] private float knockbackDuration = 0.5f;
|
||||
|
||||
public float CurrentHealth { get; private set; }
|
||||
public float MaxHealth => maxHealth;
|
||||
public bool IsDead { get; private set; }
|
||||
|
||||
public event Action<float, float> OnHealthChanged; // ★追加:HP変更イベント(現在HP, 最大HP)
|
||||
public event Action<float> OnKnockbackRequested;
|
||||
public event Action OnDeath;
|
||||
|
||||
@@ -26,6 +28,11 @@ public class EnemyHealth : MonoBehaviour, IDamageable
|
||||
col = GetComponent<Collider>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
OnHealthChanged?.Invoke(CurrentHealth, maxHealth);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (enemyAI != null)
|
||||
@@ -49,6 +56,7 @@ public class EnemyHealth : MonoBehaviour, IDamageable
|
||||
if (IsDead) return;
|
||||
|
||||
CurrentHealth = Mathf.Max(0f, CurrentHealth - damageInfo.amount);
|
||||
OnHealthChanged?.Invoke(CurrentHealth, maxHealth); // ★HP変更をUIに通知
|
||||
|
||||
if (CurrentHealth <= 0f)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user