Today we will take a look at adding in a new type of shot for our player. We already have just our basic shot and a triple shot, but now we are going to add in a laser that will expand in it’s width as it travels and will destroy everything in it’s path. This is relatively simple to adjust, as we just have to tag our new laser as “Tsunami” and add a new line of code in the enemy script to account for the interaction with this new laser.
Before we do that however, we need to actually make our laser prefab to work with. All we will do is create a duplicate of our current laser prefab and adjust our scale of it:
From here, we will want to make a new script to work with for the Tsunami because we will have new instincts that it will run with:
As we will be having the laser grow in length as it travels, we are going to have this one move upwards at a slow rate to allow it time to grow, and on top of that we will adjust it’s scale when it is on the screen:
Next, we will need to create a variable on our player to attach this new laser to, along with a new bool letting us know if the powerup has been collected:
From here, we will create a new Coroutine and void, similar to how we made our triple shot, and attach it to our Fire() void:
From here, we can just add a new if statement to our fire method:
From here, we just have to add a new line into our switch statement for the powerups script and change our range in the spawn manager script to account for the new powerup to spawn and trigger the appropriate function.
Now we can go back into our editor and see if it works as intended:
There we have it, we adjusted our sprite slightly to make it feel more “Tsunami” like and a single shot will grow and destroy everything in its path without being destroyed.