We’ve upgraded our game from a 3D prototype to a beautiful 2D Space Shooter! Now it’s time to really utilize these assets and get our game looking and feeling like something great!
And what’s an arcade-y Space Shooter without a some fun Powerups!? Let’s get down to business and destroy multiple enemies with our Triple Shot!
Create the Triple Shot
We’ve converted our Laser capsules into proper looking Laser Beams. So the first thing in creating our Triple Shot Powerup is the placement of the 3 lasers!
We’ll drag 3 laser prefabs into the Scene Hierarchy and place them as such:
Then with our lasers placed properly, we’ll throw them into an Empty Game Object — Triple Shot, and create a Prefab!
Linking the Prefab with the Player script
Now in our Player script, we’ll create a handle for the Triple Shot since this is where we’ll be Instantiating the Triple Shot from, just like the previous single Laser.
And we can’t forget to link our Triple Shot Prefab to our updated Player script:
Next we can update our FireLaser() function utilizing the bool we created for the Triple Shot, _tripleShotActivated.
Quickly before we can activate our Triple Shot, we’ll create a function to Activate the Triple Shot when called. And with it, a Coroutine to give the Powerup a limited timeframe to be used; or else it could go on indefinitely.
Creating a Global variable for the amount for the Triple Shot Cooldown:
Activating the Triple Shot
Currently we have no way to activate the Triple Shot, other than clicking on the box in the Inspector during run-time. So up next we’ll create the collectible Powerup item to activate the Triple Shot!
I’ve dragged a Triple Shot Powerup Sprite into my Hierarchy, and will have to give it a Box Collider 2D and make it a Trigger collider so that our Player can interact with it:
Then to give this Powerup Sprite functionality, we’ll create a Powerup script. In the Powerup code, we’ll give it some basic movement:
And some collision logic:
Now we can connect our Powerup script to our Triple Shot Powerup and make it a prefab:
Perfect! Our first Powerup! Remember, you can always tweak different variables to make them feel how you want for YOUR game. Every game should feel a little unique!
We still have a little bug in our code, but we’ll fix that in the next article! Then we’ll create another Powerup!