weird health problem.

Hi

this is weird, its not the first time I have made a health bar, I know that if divide the current health with the max health and then multiply it for the total length of the health bar you get pretty decent health. but for some reason its not working not

I have this:

GUI.DrawTexture (new Rect (Screen.width/6*0.45f,0, (PlayerLogic.PlayerLife / Status.Instance.PlayerLifeMax) * Screen.width/6,Screen.height/6), GraphicsManager.Instance.HealthBar);

PlayerLogic.PlayerLife is the current health, Status.Instance.PlayerLifeMax is the max health and Screen.width/6 is the total length of the health bar, but when hit I play the bar appears and then when I get just 1 hit (so my health is at 99 of 100) the healthbar disappears, Whaaaaa…???¿?¿?¿

I did Debug.Log ((PlayerLogic.PlayerLife / Status.Instance.PlayerLifeMax) * Screen.width/6); to see what was going on and on full health this gives me 170, but as soon as I get a hit the it returns 0.
I previously had a health bar with the same variables made with the same method and it worked fine, I know Playerlife and PlayerLifeMax are ok because I also have a numeric counter.

I made the calculation and 99 / 100 * 170 = 168,3.

Is it an integer division problem?
http://forum.unity3d.com/threads/36422-The-Int-Division-Problem-Unity-Edition-(Solved)

I fixed that for you.

Thanks

It is indeed an integer division problem, apparently I solved it by removing the parenthesis. I still don’t understand whats going on, in other game I had (currenthealth / Maxhealth)*healthbarlenght and it worked fine, maybe all the variables where floats I don’t remember, it was long ago. But anyways is fixed now so who cares? :lol:

Thanks! :smile: