Creating a Secondary Firing Upgrade for a 2D Shooter

DorianBurton6
1 min readOct 7, 2023

--

Further developing my game, I have created a secondary fire upgrade that gives the player a screen covering laser that lasts for a few seconds and takes out any enemies on screen.

I accomplished this by instantiating a giant laser at the players position and having it act similarly to the other lasers, just without moving. It collides with the enemies and destroys them just as a normal laser would. The laser is triggered by collecting the powerup icon, and spawns every thirty to fifty seconds.

Player Script

 public void MegaLaser()
{
_megaLaserPrefab.SetActive(true);
_isMegaLaserActive = true;
StartCoroutine(MegaLaserPowerDown());
}

IEnumerator MegaLaserPowerDown()
{
while (_isMegaLaserActive == true)
{
yield return new WaitForSeconds(8f);
_isMegaLaserActive = false;
_megaLaserPrefab.SetActive(false);
}
}

Spawn Manager

IEnumerator SpawnMegaLaserRoutine()
{
yield return new WaitForSeconds(15f);
while(_stopSpawning == false)
{
Vector3 posToSpawn = new Vector3(Random.Range(-8f, 8f), 7f, 0);
Instantiate(_megaLaserCollectable, posToSpawn, Quaternion.identity);
yield return new WaitForSeconds(Random.Range(30, 50));
}
}

The above shows how the player instantiates the mega laser and the cooldown for the player as well as the spawn routine for the powerup collectable. This all gives me a great secondary powerup that adds some spice and spawns less frequently than the rest due to its power.

--

--