- Home /
health bar questions
I want to make a health bar that is based on percents. I want the bar to go from 1-100% using guitextures. The thing I'm not sure about is the coding to comare it to large numbers.
example:
you have 1000/1000 hp when it reaches 500/1000 hp then the percent displays 50% and I want this to happen for 1-100%
Anyone know how I would go about coding this ?
Answer by kor · May 26, 2011 at 01:25 AM
currentValue / maxValue * 100 = percentage;
Also see: http://www.burgzergarcade.com/tutorials/game-engines/unity3d/001-unity3d-tutorial-health-bar-12 http://www.burgzergarcade.com/tutorials/game-engines/unity3d/002-unity3d-tutorial-health-bar-22
Im using javascript and needed to change around the code but it's only displaying 0. I'm a little confused. I've had my max and current health setup for a while now and it all works properly.
Perhaps the values you are using in your formula are whole numbers or integers (int) rather than decimals (float). If you use int values and are expecting a .5 or 1/2 value, it will display the closest whole number value. Does changing your number values to float make a difference?