using UnityEngine; using UnityEngine.UI; using DG.Tweening; using TMPro; public class MonsterHealth : MonoBehaviour { public int maxHealth = 10; public GameObject monsterShdow; private int currentHealth; public TextMeshProUGUI MonsterHp; public int CurrentHealth { get { return currentHealth; } } public Image healthBar; // °ÔÀÌÁö À̹ÌÁö // IsDead ÇÁ·ÎÆÛƼ ¼±¾ð public bool IsDead { get; private set; } private void Start() { currentHealth = maxHealth; UpdateHealthBar(); IsDead = false; // ÃʱⰪÀº »ì¾ÆÀÖ´Â »óÅ } public void TakeDamage(int damage) { currentHealth -= damage; UpdateHealthBar(); if (currentHealth <= 0) { Die(); // ¸ó½ºÅÍ »ç¸Á ó¸® } } void UpdateHealthBar() { float healthRatio = (float)currentHealth / maxHealth; healthBar.fillAmount = healthRatio; MonsterHp.text = string.Format("HP {0}/{1}", currentHealth, maxHealth); } // »ç¸Á ó¸® ¸Þ¼­µå void Die() { IsDead = true; // »ç¸Á¿¡ °ü·ÃµÈ Ãß°¡ 󸮸¦ ¿©±â¿¡ ±¸Çö // ¸ó½ºÅÍ ±×¸²ÀÚ ¿ÀºêÁ§Æ® Á¦°Å if (monsterShdow != null) { Destroy(monsterShdow); } Destroy(gameObject); } }