Need more power: Ammo collectable

Objective: Add a laser powerup that that recharges the laser allowing player to fire.

Laser power up restores lasers to full power, 15.

Create 2D sprites for laser powerup and animation using Power Point or other program. Drag these sprites into Unity Assets Laser_Powerup folder, select the sprites and set texture type to Sprite (2D & UI).

Sprites for 2D animation of laser powerup.

Create a game object by dragging powerup5_0000 into the scene, naming it Laser_Powerup. Add circle collider 2D with is trigger checked, rigidbody 2D with zero gravity and Powerup script to the Laser_Powerup game object. Set the powerup ID to 4 and assign power_up_sound from GameDevHq Filebase to be the powerup audio. Create an animation, Laser_Powerup_anim, and drag the above sprites into the animation window. Drag the Laser_Powerup into the the prefab folder and delete the game object.

Laser_Powerup game object

Add case 4 for the powerup as shown below.

OntriggerEnter2D function in Powerup script.

In the Spawn_Manager, IEnumerator SpawnPowerups() change the int powerupID from Random.Range(0, 4) to RandomRange(0,5). In Unity inspector, increase the number of powerups prefab to 5 and assign the Laser_Powerup prefab as shown below.

Spawn_Manager settings.

In the Player script, create a public void LaserPower function, shown below. This function modifies _ammo, and calls UpdateAmmo from UI manager script, noting that the _uiManager has previously be been assigned and null checked using GetComponent.

Laser power function in Player script.

Software engineer