Enemy의 이동 및 공격 로직 개선

포탈 추가
This commit is contained in:
2026-01-13 11:24:32 +09:00
parent 022bc48bc5
commit f54c4b35b9
8 changed files with 837 additions and 292 deletions

View File

@@ -1,19 +1,34 @@
using UnityEngine;
using System;
// Gate.cs
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;
if (currentHealth <= 0)
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);
}
}
}