Secondary Fire Powerup
Today, we will make a secondary powerup, that will look like this:
We need to create the powerup GameObject as well as the laser.
To make a laser, I used the sprite that is used for regular shots but I extended it on y axis and make it a little thicker.
We need to add Box Collider 2D, Rigidbody 2D with gravity set to 0 and the Laser script. Add a new tag and assign it to our new weapon.
In the Laser script, we need to set the speed to 0, so it will stay in place.
Because we won’t have to spawn multiply lasers we will move the “SuperLaset” GameObject as a child of the Player. When we collect the powerup for the secondary weapon, we will just active the GameObject. After 5 seconds we will deactivate it.
In the Player script, we will create a new variable of type GameObject called _superLaser.
Create a new method and a new coroutine. In the SuperLaserActive() method we need to active the GameObject and start the coroutine.
In the coroutine, after 5 seconds, we will deactivate our secondary weapon.
In the Powerup script add a new case to the switch statement:
Now, we will make the powerup GameObject for our laser. Im using a sprite of a laser gun for our powerup.
Change the name, add the Circle Collider2D and Rigidbody2D, and set gravity to 0. Add Powerup script and assign the sound effect. Change PowerupId to 5. Add the Animation for color shifting.
Make a prefab and add it to the Spawn Manager script.