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