Our game is really shaping up now! We have taken it from simple cubes and capsules to a work of art with full 2D artwork and animations. It has enemies and a starry setting to fly around in. It is by no means finished yet but it is much further along than when we first got our players moving!
Our next phase of pushing our games towards the finish line is to give the player more power! We are going to create our first power-up, the triple shot! Nothing says power like 3 lasers instead of one, right?
Our first step in creating this new power up is to drag 3 copies of our laser prefab into our scene. We want to make sure to reset their transforms to (0,0,0) by selecting the 3 stacked dots icon to the upper right corner of the transform component and selecting the reset option.
Now we want to group the lasers together, so we are going to create an empty game object and group them together under that new object, let’s rename that container to Triple_Shot and reset its transform too.
Now last place our player back at (0,0,0) so that we can position out lasers in our container relative to the location of the player object when it spawns them. Use the mine tool to reposition the lasers to come out of the front of the ship and its wings. Once the lasers are positioned, dragged the Triple_Shot object to our prefabs folder to create it as a prefab.
Now delete the object from the hierarchy, and we can place our player back to where we had it (in my case, it was moved down 2 units on the y-axis in the center of the play space).
Next, we need the logic that will determine which of our players laser prefabs will be instantiated when the player presses the fire input. We will need a boolean property on the player class to track if the Triple Shot is active.
We also need to pass in our Triple Shot prefab so that we can use it in the instantiation code.
Now we can modify our players fire code to look like
Hopping back into Unity, we can drag our Triple Shot prefab into the spot on the player component and test our game. Manually checking the Triple Shot Active check box on our player component while the game is running should result in our new Triple Shot being used in place of the single laser when we fire.
That’s it for today, we still have to create the power up collectible object and set it up to activate our Triple Shot Active flag on the player but that can come tomorrow, when we look at animating sprites for our power up collectible. If you enjoyed this article, or want to come along with me as I progress on my journey, follow me at gamedevchris.medium.com.