Adding a secondary firing mode to my space shooter
Right now, I only have the triple-shot as an additional firing mode. I’m going to add another, but I want it to be special. More powerful and more rare. One of my favorite types of weapons in shooting games are railguns, so I’ll make one for my game.
First, I made a prefab object for my new projectile. I found some art that worked and also created a new script to handle its logic. The projectile will simply appear on the screen and stay stationary, and fade away over a quick period then disappear. I made a coroutine in the railgun script to handle this fade-away. It waits for half a second, then starts reducing the alpha component of the sprite until it gets to .15, then destroys the object completely. This routine is called as soon as the projectile is instantiated.

I added some new logic to the player script so it can fire railgun projectiles if enabled.

Now that everything is squared away with the player and railgun, I need to create a system to spawn the powerup. I want this powerup to be special and rare, so I don’t want to include it in the same group as the normal powerups. In the spawn manager script, I created a new array reserved for *special* powerups and added the new railgun prefab to it. I only want the special powerups to spawn 1/10th of the time, so I’ll modify the spawn logic a bit.
I’m creating a random integer between 1 and 10. If it’s 3, it will spawn something from the special powerups group. Otherwise, it spawns another normal powerup.

