코드 리팩토링
재사용성 및 확장성을 고려하여 코드 전반을 리팩토링함
This commit is contained in:
@@ -1,24 +1,21 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class Core : MonoBehaviour, IDamageable
|
||||
/// <summary>
|
||||
/// Core structure that players must defend.
|
||||
/// Uses HealthComponent for health management.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(HealthComponent))]
|
||||
public class Core : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float maxHealth = 100f;
|
||||
[SerializeField] private float currentHealth = 100f;
|
||||
private float CurrentHealth;
|
||||
private HealthComponent _health;
|
||||
|
||||
// 체력이 변경될 때 UI 등에 알리기 위한 이벤트 (Observer 패턴)
|
||||
public static event Action<float> OnHealthChanged;
|
||||
public static event Action OnCoreDestroyed;
|
||||
|
||||
void Awake() => currentHealth = maxHealth;
|
||||
|
||||
public void TakeDamage(float amount)
|
||||
void Awake()
|
||||
{
|
||||
currentHealth -= amount;
|
||||
OnHealthChanged?.Invoke(currentHealth / maxHealth);
|
||||
|
||||
if (currentHealth <= 0)
|
||||
OnCoreDestroyed?.Invoke();
|
||||
_health = GetComponent<HealthComponent>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the health component for direct access.
|
||||
/// </summary>
|
||||
public HealthComponent Health => _health;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user