Unity Level Tracker
Unity
I built an app with three separate timers: A 5 minute timer, 10 minute timer, and 30 minute timer. When I turn these timers on, I get experience automatically when they fill, and I can add additional experience as I achieve personal milestones.
Scaling Experience Exponentially
Conquering experience scaling is actually rather mathematically involved.
The Exponential Equation
Using Mathf.Pow, I was able to scale the amount of experience required to level up by using an exponential equation:
y = ab^2
Every level up, a new Max Experience value is calculated by using the current level as the scaling factor of a constant (rate of change) multiplied by the original value of Max Experience at level 1.
So the equation is:
​
MaxExperience = value at level 1 x rate of change^(current level)
MaxExperience = 1000 x 1.1^CurrentLevel
Level Up Events
There were a few details I had to really pay attention to and think about logically to get effects similar to what you’ll see in a lot of Pokemon games.
Experience Bar Glow
This effect I achieved by using a Coroutine to fluctuate the alpha value of a white image that overlays the experience bar itself.
Carry Over Experience
After leveling up, the CurrentExperience may overshoot the MaxExperience, and if not accounted for, will be lost as you try to progress to the next level.
Using a series of yield statements in a Coroutine, I simply subtracted the MaxExperience from CurrentExperience on level up, that way a _carryOverExp variable can be used to add the CurrentExperience if there is any.
Smooth Increase
Without using a coroutine to iterate the fill amount of the experience bar, the experience bar will have to simply snap to the new fill value, which is rather boring. I love how Pokemon has this effect in it, so I went ahead and used a coroutine to gradually increase the experience bar when experience is gained, and then Level Up! if the experience bar gets full during the coroutine.