Created
October 30, 2021 01:05
-
-
Save curious-username/79d2efb15479ef629c3f899ccda98b69 to your computer and use it in GitHub Desktop.
shield life system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int _shieldLife = 3; | |
[SerializeField] | |
private GameObject _shield; | |
private bool _isShieldActive | |
void Start() | |
{ | |
_shieldDamage = _shield.GetComponent<SpriteRenderer>(); | |
} | |
public void Damage() | |
{ | |
switch (_isShieldActive) | |
{ | |
case true: | |
_shieldLife--; | |
if (_shieldLife == 2) | |
{ | |
_shieldDamage.color = Color.magenta; | |
} | |
else if(_shieldLife == 1) | |
{ | |
_shieldDamage.color = Color.red; | |
} | |
else { | |
_isShieldActive = false; | |
_shield.SetActive(false); | |
_shieldDamage.color = Color.white; | |
_shieldLife = 3; | |
} | |
break; | |
case false: | |
_lives--; | |
_uiManager.UpdateLives(_lives); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment