Phase 1: More FirePower
Objective: Add more fire power options for the player.
We will implement 2 new powerups. The first will be an EMP blast that will destroy all enemies in the game screen. There will be no time limit or cool down just one single shot stored just incase the players ammo runs out before a refill comes along. The EMP switch will be set to the E key and if there is no EMP available will play an empty sound similar to when the player is out of ammo.
The second powerup I call Chaos. When it gets activated the player will get ammo fully restored and the player ship will spawn a 7 point direction multi gun attachment under the ship. When Chaos is active the player will not lose ammo for the 5 seconds that it remains active before the gun attachment is disabled and normal laser shot is back as the main gun.
We’ll start with creating the powerup collectables. Drag the sprite images into the hierachy like before, rename them, add rigidbody 2d and collider 2d to each setting the colliders as triggers and turning off gravity in the rigidbody. Add the powerup script and set the powerup IDs and sounds.
Next animate the collectables like we did previously, then assign the new powerups to the spawn manager powerup array and update the spawn manager script to allow random spawning of the new powerups.
Next in the player script create serialized gameobjects for the chaos guns prefab and the emp blast prefab and assign them in the inspector, along with private bools to check if either powerup is active(_isChaosActive etc).
Create the activate methods for both and a coroutine cool down for the chaos powerup, then set both to isactive and refill the ammo in the chaos before starting the cooldown coroutine.
Next update the powerup switch statement adding new cases for the collectables and call the players public activate methods on the OnTriggerEnter method.
Next for the EMP blast check if the E key has been press then run an if statement to check if the EMP is active and if not play the empty ammo assigned sound. If the EMP is active fire the EMP and set active to false.
Finally within the ShootLaser, an else if statement to the already set logic to check if the Chaos is active then spawn the lasers out all 7 shooters at angles.
In the next post, we will set up a camera shake effect.