Unity Guide
Implementing space shooter game features - Freezing power-up
A quick review of new features added to a space shooter game in Unity
Objective: Implement a negative power-up item that harms the player in a space shooter game with Unity.
In the previous post I implemented a new spawning system in my space shooter game with Unity. Now it’s time to implement a power-up that negatively affects the player if it’s collected.
New sprites
To begin, we need to include the new sprites to visualize the new power-up item and the respective effect in the player. If you don’t know where to create or obtain new sprites, then I recommend you to use a free and online program (like I did):
Freeze effect
To display the freeze effect in the player, I’ll use these sprites to create a new animation:
If you don’t know how to animate sprites in Unity, you can visit one of my older posts:
Once I create the animation I need to determine the keyframes of the sprite flow so that the effect takes place correctly:
Also, in order to display the animation when the player collects the power-up, we need to modify the animation controller by adding a trigger that triggers the animation and then returns to the normal state of the player:
Freeze power-up item
Now, let’s add the respective power-up to the game by using new sprites. If you don’t know how to implement a power-up in Unity, you can visit one of my older posts here:
Let’s create and modify the keyframes of a new animation and add the respective components to the power-up:
Once the components fit our needs, let’s make the power-up a prefab and add it to the spawn manager power-ups array to be spawned:
Implementing the power-up
In order to implement the power-up and visualize it’s effects, let’s open the Powerup script and add the new case inside the switch statement that handles the collision with the player:
Then, let’s open the Player script and create a new variable to hold the reference to the animator component attached to the player, which we’ll initialize in the Start method using GetComponent:
Then, in the method that enables and handle the power-up effects, let’s add the respective case for the new freezing power-up. The effect will stop the player’s movement and display the freezing effect by modifying the speed variable and triggering the animation:
Finally, in the method that gets called to disable a temporal power-up, let’s apply the original value to the speed variable:
And now, if we run the game in Unity, we’ll see that the power-up spawns and applies the expected freezing effect in the player for a couple of seconds:
And that’s it, we implemented a negative power-up to freeze the player! :D. I’ll see you in the next post, where I’ll be showing more features added to my space shooter game in Unity.