Collecting multiple shield charges

Objective: Allow the player to collect up to three shields and provide visual effect for each level.

Three levels of shield provide more protection. Order of layer is important to give the effect.

Duplicate the Player Shield twice setting all three shields to inactive.

Game object for each shield level.

Reduce the scale of Shield (1) and Shield (2) to respectively 1.4 and 1.0. Change sprite renderer color as shown below. Also change the order in layers to allow each shield level to stand out from each other. The Player game object is layer 4 and the engine damage is layer 5.

Shield game object settings.

Add the variables below to the Player script.

Player script excerpt.

The _playerShield is an array and assigned in the inspector, shown below.

Player shield within Player script on Player game object.

ActivateShield() function increments _shields after collecting the Shield_Powerup and turns on the shield animations based on shield level.

ActivateShield() function in Player script is called when powerup is collected.

DamagePlayer() function uses the _shields to detect when shields are active. The _shields loses a level and the animation for the highest active level shield is inactivated.

Shields protect player from damage.