fgm24/Assets/Scripts/HeathSystem/DestroyOnNoHealth.cs

25 lines
507 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(HealthComponent))]
public class DestroyOnNoHealth : MonoBehaviour
{
HealthComponent health;
private void OnEnable()
{
health = GetComponent<HealthComponent>();
health.OnHealthZero.AddListener(OnDeath);
}
private void OnDisable()
{
health.OnHealthZero.RemoveListener(OnDeath);
}
private void OnDeath()
{
Destroy(gameObject);
}
}