Tiny bug, and functional programming

Hi!

There is a little bug here. The ReduceHealth method subtracts damage from currentHealthPoints. The if statement then check if currentHealthPoints - damage < 0, so the player is actually killed before he dies.

Example:
CurrentHealthPoints=15, damage =10

After the call to ReduceHealth, currentHealthPoints = 5,
In the if statement we then check if curentHealthPoints - damage <= 0 (5-10 = -5 <= 0) and we Kill the player.

I know this isn’t the topic of this course, but does anyone have any experience in trying to use a somewhat functional approach to Unity development? In the above example you instead could have a function CalculateNewHealth, that returns the new currentHealthPoints and have both currentHealthPoints and damage as input parameters.

/Björn

Privacy & Terms