24 lines
684 B
C#
24 lines
684 B
C#
using UnityEngine;
|
|
using System;
|
|
|
|
public class Core : MonoBehaviour, IDamageable
|
|
{
|
|
[SerializeField] private float maxHealth = 100f;
|
|
[SerializeField] private float currentHealth = 100f;
|
|
private float CurrentHealth;
|
|
|
|
// 체력이 변경될 때 UI 등에 알리기 위한 이벤트 (Observer 패턴)
|
|
public static event Action<float> OnHealthChanged;
|
|
public static event Action OnCoreDestroyed;
|
|
|
|
void Awake() => currentHealth = maxHealth;
|
|
|
|
public void TakeDamage(float amount)
|
|
{
|
|
currentHealth -= amount;
|
|
OnHealthChanged?.Invoke(currentHealth / maxHealth);
|
|
|
|
if (currentHealth <= 0)
|
|
OnCoreDestroyed?.Invoke();
|
|
}
|
|
} |