Made With Unity | 2D Space Shooter Part 13: Adding Effects (VFX)

Adding a simple sprite explosion effect to our enemy when it gets destroyed, some nice effects to our player and starting the game when destroying a asteroid.

ENEMY

Creating The Animation Explosion

Will drag the Enemy prefab to the Hierarchy and press Open

Selecting the Enemy will add a Animator component and create a controller called EnemyController.

Using the Animation windows and still selecting the Enemy object will create the animation explosion. Selecting the enemyExplotion_anim will remove the check from Loop Time on the Inspector window.

To control when to call for this animation we need to use a new window called Animator

On the Parameters section, hitting on the plus sign will create a Trigger named EnemyDestroyed, will create a new empty state and Set as Layer Default State.

Select the New State and using Inspector window will name it Empty State

Right clicking the Empty State will Make Transition to the enemyExplotion_anim and select the EnemyDestroyed in the Conditions

On the Hierarchy press the arrow to be back to the normal view.

Updating The Enemy Script

In the Enemy script will add 3 new variables

On the Start() method will add the necessary reference for the newly added variables

Added a new method, OnEnemyDeath(), and calling it where the Enemy will receive damage by either the Laser or the Player. To let the animation run we must first turn _speed to 0, play the animation, _boxCollider2D.enebled need to be false so the player will not get impacted with the Enemy collider while the animation runs; now on the Destroy() we added the 5 so it will destroyed the Enemy object in 5 second.

PLAYER

Thruster

Will start to drag all the sprites that belong to the Thruster animation for the Player to the Hierarchy. By default Unity will prompt you to save the new animation; create a new folder on the Animation folder called Thruster and the new animation thruster_anim

Rename the new object as Thruster and drag it inside the Player

Make the necessary edit on the Transform component and on the Sprite Renderer component add a 1 as the Order in Layer.

Hurt Animation

Will repeat the same steps as the Thruster but this time I will two new object to my Player to represent the hurt animation on two engines.

Turned off the two object engine

Updating The Player Script

Will add the following variables to the Player script and drag the LeftEngine and RightEngine to the fields from the Inspector.

Will add the following switch statement to our DamagePlayerLives() method

ASTEROID

Explosion Effect

Will add a Asteroid sprite to the Hierarchy, add a Circle Collider 2D and create a new script called Asteroid.

Will repeat the step to add a explosion effect to our Asteroid

Asteroid Script

Updating The SpawnManager Script

🎮PART 14🎮

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store