using UnityEngine; using System; public class Gate : MonoBehaviour, IDamageable { [SerializeField] private float maxHealth = 50f; [SerializeField] private float currentHealth = 50f; private float CurrentHealth; // 체력이 변경될 때 UI 등에 알리기 위한 이벤트 (Observer 패턴) public static event Action OnHealthChanged; public static event Action OnGateDestroyed; void Awake() => currentHealth = maxHealth; public void TakeDamage(float amount) { currentHealth -= amount; OnHealthChanged?.Invoke(currentHealth / maxHealth); if (currentHealth <= 0) { gameObject.SetActive(false); var obstacle = GetComponent(); if(obstacle != null) { obstacle.carving = false; obstacle.enabled = false; } OnGateDestroyed?.Invoke(); Destroy(gameObject, 0.1f); } } }