Geek Culture
Published in

Geek Culture

Space Shooter Challenge: Secondary Fire Pt 1

My main intention for secondary fire is to add heat-seeking missiles. But my son has been insisting on me putting a big laser in the game.

I simply took the existing Laser sprite and added it as a child of the Player object. To get the desired visuals, I scaled it on the Y axis by 8 and positioned it correctly on the Player.

For the functionality, I made a public method for the Powerup script to call. In this method, I start a Coroutine. This Coroutine sets the assigned game object active before waiting, then turning it off again.

Originally, I just added a Box Collider 2D and Rigidbody 2D then set the Tag to Laser. But on collision with an enemy, Destroy is called on the laser. I want this laser to be indestructible and overpowered for five seconds, so instead I added a new Tag and checked for it on the Enemy Collision method.

Again, I repurposed my Powerup sprites into a suitable Super Shot Powerup.

Then, set it up to mimic the other Powerup prefabs, add a new ID, and animate it. In the Powerup script, I simply added to the switch statement, and called the new public method I created on the Player.

--

--

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