RegenerateHealth different approach

To start off sorry if there are some grammar mistakes in here. Unfortunately I am not a native english speaker.
It bothered me how the health system was handled when you have a level up. The situation is, that when you play the game and your health stats are at e.g. 60% and you have a level up you automatically jump to 70%. The problem here is that this also happens when you are above 70%. Like when you are at 90% health and you have a level up, health changes to 70%. Of course it just looks like the player loses health. But it bothered me anyway.
I already changed that in my code.

private void RegenerateHealth()
  {
     float tempRegenPercentage = Mathf.Max(currentHealthPercentage, regenerationPercentage);
     healthPoints = GetComponent<BaseStats>().GetStat(Stat.Health) * tempRegenPercentage / 100;
   }

I’ve set the variable ‘currentHealthPercentage’ in ‘Update’. It may not be very elegant but it works for me. If you have any ideas on how to make it better, it would be nice if you’d let me know.
Feel free to use if you want.

2 Likes

Nice approach. Thank you for sharing.

Privacy & Terms