Why is my equation only working once?

I have an equation for how much experience is needed to level up: newreqxp = Mathf.Floor(reqxp * Mathf.Pow(1.1f, level)); I then have an if statement for leveling up:

if (xp == newreqxp) { level += 1f; xp = 0f; newreqxp = Mathf.Floor(reqxp * Mathf.Pow(1.1f, level)); }
I have reqxp set to 5, and level starts at 0, and the first time it works. I get 5 xp, and level up, but after that, it stops. I still get xp fine, but I don’t get levels, and it just increases xp indefinitely. Both of these were in the Fixed Update function, then I moved the newreqxp equation to the Start function to see if that would fix it. It did not. Is there a way to fix it? If you need more information, let me know.

Your problem is your if condition. Floating point values will almost never be equal. So as you gain xp, you most likely will overshoot your desired target value. So you should change your condition to a “greater or equals” and instead of setting xp back to 0 you may just subtract “newreqxp” from xp. That keeps any overshoot for the next level. If you can gain large amounts of xp at once, you may even replace the if with a while like this:

while (xp >= newreqxp)
{
    level += 1f;
    xp -= newreqxp;
    newreqxp = Mathf.Floor(reqxp * Mathf.Pow(1.1f, level));
}