I’ve added two new powerups to the 2D Space Shooter game. The first one refreshes ammo and the second one adds one player life back.
Adding additional ammo is easy. I just duplicated my existing Powerup prefab, changed the Sprite and animation and added the following code to set the ammo back to its maximum value.
public void RefillAmmo()
{
_ammoLeft = _maxAmmo;
UpdateAmmoLeft(_ammoLeft);
}
As mentioned in the previous post, the UpdateAmmoLeft is a delegate that updates the UI.
As for adding player life, again I duplicated a prefab and changed its Sprite and animation. When player collides with the power up, it will add one to life, update player life UI and remove one engine that is damaged.
public void Heal(int life=1)
{
if (_lives < 3)
{
_lives += life;
_uiManager.UpdateLives(_lives);
switch (_lives)
{
case 3:
_leftEngineHurt.SetActive(false);
break;
case 2:
_rightEngineHurt.SetActive(false);
break;
}
}
}
I also updated SpawnManager to be able to spawn the two additional powerup.
The two new power ups are now available in the game.