Creating a new weapon. The “Combustion Laser”

Objective: create a secondary fire weapon for the player

In this challenge I created a new fire weapon called “Combustion Laser”. These lasers explode and cause area damage.

The first thing is to duplicate the laser prefab to have the same components and change the size and the color until it looks as you like. But I deleted the laser script and created a new script for this prefab.

In the combustion laser script I added the same movement behaviour and empty function called Explode that I filled later.

We have the prefab ready to use.

Next step is to create a “Combustion” prefab, it is gonna be a copy of the explosion prefab.

Then we have to add the collider2d and the rigidbody2d components.

Now we have to open the “Combustion Laser” prefab and add some “Combustion” as a child, they are gonna be disabled as default.

In the combustion script we are going to add the following code to the Explode function. In this code we get all childs of the combustion laser and activate each one through a for each loop.

Then in the enemy script we have to check for the collision with the combustion laser to call the explode function and the collision with the combustion to kill the enemy.

The prefab is ready but the player is not able to use it.

We are gonna drop a sprite in the scene to create a new powerup to activate the combustion laser weapon, and add this powerup to the powerup array in the spawn manager.

Then In the powerup script we have to add a new case for the ID 5 to activate the combustion laser.

In the player script I declared a new variable called “_isCombustionLaserActive” and in the Shoot function used a conditional to check if this variable is true to instantiate a combustion laser prefab instead of a regular laser.

Last step, in the spawn manager script I added in the SpawnPowerupRoutine a new variable called “probability”. Then generate a random number between 0 and 20 and if the value generated is equal to 0 then the spawn manager has to instantiate a combustion laser collectable. It makes this powerup appear less likely than the others.

And that’s it! The new combustion laser powerup is ready for the action.



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
Rusben Guzman

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.