2D Galaxy Shooter: Shield Strength

Anurag Chawla
2 min readMay 30, 2021

Shield that can take 3 hits and shows a visual change as it takes damage.

Here is another feature that increases the strength of the shield power-up. As of now it can only take one hit of damage before being deactivated completely.

In order to take this effect , when player collided with Shield PowerUp

In PowerUp.cs script when OnTriggerEnter2D method called — It will call player.ShieldPowerUpActive() having _powerupID =2 for shield PowerUp when Player collided it.

This will communicate with Player.cs script where method ShieldPowerUpActive() implemented as below

ShieldPowerUpActive() method In Player.cs script

Here setting few variables such as

_isShieldPowerUpActive sets to true, _shieldStrength=3 so that shield have a strength of 3, the _ShieldVisualizer Renderer component having material.color set to gray as default and SetActive(true) so that shield visualizer is visible .

When the enemy hit the player in enemy.cs script, OnTriggerEnter2D method is called — it will call the player.Damage() method where we implement the main logic for shield visualizer if the player having ShieldVisualizer active.

Logic for Shield Visuals based on the Shield Strength

As soon as player is hit by the enemy having shield visualizer active, its _shieldStrength keep decrementing one by one and based on the shield strength it changes color from default gray to green to red..and finally when again hit it loses its life

Another Feature- Visualizer Shield Strength

Note: during the life of shield strength — player not loses its life by changing the color of shield…This feature having..

  • Visualize the strength of the shield with changing color on the shield.
  • Allow for 3 hits on the shield to accommodate visualization

--

--

Anurag Chawla

Emerging Technologies - Power Virtual Agents | AI Chatbots | Multi-Cloud & DevOps | UI Technologies - React , Angular | Gaming Technolgies - Unity, XR- AR/VR