Destroy game object with delay and then play death animation

I have a game object that gets attacked, and once health == 0, I run Destroy(gameObject,1).

Once that happens, I want to play my death animation which is simply falling to the right and fading out at the same time. I could create an animation and run that, but to save lots of time as I have many sprites, I realised I can use Transform.rotate and set the alpha lower over time. The problem is that once destroy has been called, the game object is disabled so I cannot use coroutines or the update function to rotate and change the alpha.
Is the only way to do this by making a frame by frame animation of a sprite rotating and fading away?

Put the controlling logic on another GameObject that hosts the death animation, such as a death animation prefab, and then have it kill itself off when the death animation is done.

I do this all the time in my games anytime an sprite enemy is exploded, he gets replaced by an animated prefab sprite explosion animation, which then cleans itself up after it is done.

1 Like