Damages via Animated VFX
In video games, there are usually 2 ways players will know if they took damage: Visual effects, like explosions, and user interface, like a heads-up display. Even though notifying the player via the user interface is straight to the point, adding visual effects can bring home the point of the player getting damaged.
There are many ways to display damage using visual effects. For instance, in FPS, the player might see more blood as they take more damage. On the other hand, in action and adventure games, the screen might flicker to show the player has taken damage. However, because our game is a 2D space shooter, we’ll implement damage visual effects via animated sprites. Moreover, because the sprites are the same, we can create one and duplicate it for the other.
Once the engine fire animated sprite is created, it’s time to duplicate it and place it on the player.
Now we now can focus on the scripting part.
Simple Yet Effective Implementation
Because this animated sprite will only be used on the player, we can add the logic right in the Player script. The first step is to create a variable so we can reference the objects we just created.
After referencing the engine fire in the Inspector panel, we just have to disable them at the Start.
Now, all we have to do is whenever the player takes damage, we just enable one engine.
Because the player only have 3 lives before dying, all we need to do is enable each engine fire animation when the player only has 1 and 2 lives remaining.