33 lines
795 B
C#
33 lines
795 B
C#
using UnityEngine;
|
|
|
|
public class EnemyHealth : MonoBehaviour, IDamageable
|
|
{
|
|
public float maxHealth = 50f;
|
|
private float _currentHealth;
|
|
|
|
void Start()
|
|
{
|
|
_currentHealth = maxHealth;
|
|
}
|
|
|
|
public void TakeDamage(float damage)
|
|
{
|
|
_currentHealth -= damage;
|
|
Debug.Log($"{gameObject.name} 남은 체력: {_currentHealth}");
|
|
|
|
// 데미지 입었을 때 반짝이는 효과를 여기서 호출해도 좋습니다.
|
|
// 예: GetComponent<EnemyAttack>().StartFlash();
|
|
|
|
if (_currentHealth <= 0)
|
|
{
|
|
Die();
|
|
}
|
|
}
|
|
|
|
private void Die()
|
|
{
|
|
Debug.Log($"{gameObject.name} 사망!");
|
|
// 여기서 파티클 생성이나 점수 추가 등을 처리합니다.
|
|
Destroy(gameObject);
|
|
}
|
|
} |