Objective: Create a powerup to give the player more missiles.
We’ve created missiles, given them the ability to hunt down enemies, and given them an UI element to visually show how many missiles the player has. However, we have not given the player any way to gain more missiles. Today we are going to do this by creating a powerup.
To begin we need to import a sprite into the hierarchy. Size it, and color it accordingly, then prefab the sprite by dragging the sprite into the prefab folder.
Attach the powerup script to the prefab and assign an id number and the audio clip in the inspector.
Open the powerup script and we need to add a case to the switch function.
The method mentioned in the switch, we need to create that method in the player script. What do we want the method to do? Add 1–3 missiles to the player.
We need to adjust the spawning manager. We want this to be a rare powerup, so we are adding this to the rare powerup coroutine. This means it has a chance to spawn once every 20 to 30 seconds.
Now the powerup is ready. The missile powerup will spawn rarely and give the player 1–3 more missiles. This keeps the powerup missile in play for longer. This is all there is for the player missiles. As I always say, don’t be afraid to experiment with your code, and I’ll see you in the next tutorial!