Visualizing Shield Strength and Adding Shield Lives

[SerializeField]
private Color[] _shieldLifeColor;
private int _maxShield = 3;
private int _shieldLife = 0;
private void UpdateShieldAppearance()
{
if (_shieldLife > 0)
{
SpriteRenderer renderer = _shields.GetComponent<SpriteRenderer>();
renderer.color = _shieldLifeColor[_shieldLife - 1];
}
}
public void ShieldsActive()
{
_shields.SetActive(true);
_shieldsActive = true;
_shieldLife = _maxShield;
UpdateShieldAppearance();

}
private void DamageShield()
{
_shieldLife--;
UpdateShieldAppearance();

if (_shieldLife == 0)
{
_shieldsActive = false;
_shields.SetActive(false);
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store