Instead of plainly destroying the slime’s gameobject, I implemented a DeathSequence Coroutine that I call in DetectDeath()
:
private void DetectDeath()
{
if (currentHealth < 0)
{
StartCoroutine(nameof(DeathSequence));
}
}
IEnumerator DeathSequence()
{
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
WaitForEndOfFrame wf = new WaitForEndOfFrame();
GetComponent<Collider2D>().enabled = false;
for (int i = 0; i < 60; i++)
{
spriteRenderer.enabled = !spriteRenderer.enabled;
yield return wf;
}
Destroy(gameObject);
}
It’s simple enough but does give some nice little feedback…