In my game I am creating the player can be shielded with a shield that absorbs x amount of damage. Basically when a player has a shield any damage going in to that player will have to pass a (is shielded) check. Then say the enemy deals 100 damage to the player and the shield absorbs 50 damage then I would obviously want the shield destroyed and the players health to be at 50.
The code works but I was wondering if there was a more elegant way to solve this problem.
Please let me know
public void TakeDamage(float Damage)
{
if (shielded == true) {
float damageInflicted = Damage;
if (damageInflicted > shieldAmount) {
float damageRemaining = Damage - shieldAmount;
shieldAmount -= Damage;
currentHealth -= damageRemaining;
} else {
shieldAmount -= Damage;
}
} else {
currentHealth -= Damage;
}
}