Files
ProjectMD/Assets/Scripts/GameBase/Gate.cs
2026-01-13 11:24:32 +09:00

34 lines
1002 B
C#

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<float> 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<UnityEngine.AI.NavMeshObstacle>();
if(obstacle != null)
{
obstacle.carving = false;
obstacle.enabled = false;
}
OnGateDestroyed?.Invoke();
Destroy(gameObject, 0.1f);
}
}
}