36-Visual Effects of Enemy Explosion
In this post, we will add an explosion effect to the enemy when it gets destroyed.
The steps are as follows:
- Since the animation is dedicated to the enemy, we can add the enemy explosion animation to the enemy prefab
- Add an OnEnemyDeath trigger to switch the animation state from default to explosion and vice versa
- Get a handle to the animator to control the trigger value
- Trigger the animation before destroying the enemy (since the animation takes some time to play, we cannot destroy the enemy parent immediately. Instead, wait a few seconds before destroying the enemy; remove the enemy’s collider component so that the player cannot keep scoring on the same enemy and the enemy won’t hurt the player after it is destroyed)