Files
ProjectMD/Assets/Scripts/GameBase/Gate.cs
Dal4segno db5db4b106 코드 리팩토링
재사용성 및 확장성을 고려하여 코드 전반을 리팩토링함
2026-01-21 01:45:15 +09:00

52 lines
1.2 KiB
C#

using UnityEngine;
using UnityEngine.AI;
/// <summary>
/// Gate structure that can be destroyed.
/// Uses HealthComponent for health management.
/// </summary>
[RequireComponent(typeof(HealthComponent))]
public class Gate : MonoBehaviour
{
private HealthComponent _health;
private NavMeshObstacle _obstacle;
void Awake()
{
_health = GetComponent<HealthComponent>();
_obstacle = GetComponent<NavMeshObstacle>();
// Subscribe to health component events
_health.OnDeath += HandleDeath;
}
void OnDestroy()
{
if (_health != null)
{
_health.OnDeath -= HandleDeath;
}
}
private void HandleDeath()
{
// Disable the gate visually
gameObject.SetActive(false);
// Disable NavMesh carving so enemies can pass through
if (_obstacle != null)
{
_obstacle.carving = false;
_obstacle.enabled = false;
}
// Destroy the object after a short delay
Destroy(gameObject, 0.1f);
}
/// <summary>
/// Get the health component for direct access.
/// </summary>
public HealthComponent Health => _health;
}