Strange transform.localscale foreground error

I just finished the lecture on updating the health bar to the enemies actual health. Everything is functional and works as expected. However there is a warning that I cant seem to fix, nor do I understand the reason, my code in “HealthBar.cs” is the same as Sam’s. Any help? Thank you!

GetFraction returns null. Check healthComponent.GetFraction(). I guess this part {NaN, 1, 1} where NaN means not a number.

Thanks for the info, however it seems the problem has gone on its own, possibly was just a weird unity bug. I will check this again if the error comes back. Thanks!

It’s existing in the first place highlights a structural defect… NaN (Not a Number) is UnitySpeak for “Division by Zero”… What this means is that at some point the game thought your max health was zero. It’s often a good idea to check for division by zero before calculations such as these.
Example:

public float HealthAsPercentage(){
{
     return MaxHealth!=0?currentHealth/MaxHealth:0;
}

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

Privacy & Terms