Day 32 — Improvments: visualizing shield strength

private int _shieldHealth;
private SpriteRenderer _shieldVisualHealth;
public void Damage()
{
if (collectedShield == true)
{
_shieldHealth -= 1;
switch(_shieldHealth)
{
case 0:
Destroy(_shield.gameObject);
collectedShield = false;
break;
case 1:
_shieldVisualHealth.color = Color.red;
break;
case 2:
_shieldVisualHealth.color = Color.yellow;
break;
case 3:
_shieldVisualHealth.color = Color.magenta;
break;
default:
Debug.Log("Something has gone wrong with the Shield Health");
break;
}
}
}
public void EngageShieldPowerup()
{
_shield = Instantiate(_shieldPrefab, transform.position, Quaternion.identity);
collectedShield = true;
_shieldVisualHealth = _shield.GetComponent<SpriteRenderer>();
_shieldHealth = 4;
}
Color newColor = new Color(0.3f, 0.4f, 0.6f, 0.3f);

--

--

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