lucid-super-dream/Assets/Scripts/DisableOnDeath.cs

35 lines
737 B
C#
Raw Normal View History

2021-01-05 13:10:20 +01:00
using DG.Tweening;
using UnityEngine;
using Weapons.Scripts;
[RequireComponent(typeof(EntityHealth))]
public class DisableOnDeath : MonoBehaviour
{
private EntityHealth _health;
private void Awake()
{
_health = GetComponent<EntityHealth>();
}
private void OnEnable()
{
_health.Die += Die;
}
private void OnDisable()
{
_health.Die -= Die;
}
private void Die()
{
var oldName = gameObject.name;
gameObject.name = "disabled";
transform.DOScale(Vector3.zero, 0.33f).SetEase(Ease.InBack).OnComplete(() =>
{
gameObject.name = oldName;
gameObject.SetActive(false);
_health.Reset();
});
}
}