Carrying current health percentage into new level

In this lecture, we made a variable regenerationPercentage to provide a minimum health percentage to regenerate upon leveling up. I was interested in how to set this minimum value based on the health percent remaining at level up, so I did the following steps.

Added a new public event Action beforeLevelUp
Placed the call to this right before the currentLevel = newLevel in the UpdateLevel method
Subscribed with a “CarryoverHealth” method in Health.cs
The method contains regenerationPercentage = GetPercentage();

Upon leveling up, there’s a quick (?) call to set the regenerationPercentage for the Health script, which is then used as the minimum health value in the RegenerateHealth method. Now, if my character is at 30% when leveling, it only regenerates to 30% after the level up.

Was this the right solution?

Looks like a working solution to me.
Although we opted for a different system that looks to be a good way to use events :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.