- Home /
10 Health = 100% health bar length?
Hello, this is the first time I have had to post here for help and I am more than sure that this is such a really simple error that I can not spot.
So I think this might be more of a mathematical question, although I am not too sure.
My character starts off with 10 Hit Points, and he obviously also has a level of 10 Hit Points.
I have a health bar that was at one stage working, but then when I tried to implement the gaining of experience and leveling up, everything went to hell.
Currently, all of my other experience bars and level bars are working, but for some reason I cannot get the health bar to work.
Here is the code I have for the health script, written in C#
void Update () {
percentOfHealth = curHealthXp / healthLevel;
healthBarLength = percentOfHealth * 746;
percentOfHealthXp = curHealthXp / maxHealthXp;
HealthXpBarLength = percentOfHealthXp * 200;
}
And here is the code that I have written for the GUIHandler Script.
void OnGUI() {
GUI.DrawTexture (new Rect (Screen.width / 4 + 6, Screen.height - 70.5f, LevellingSystem.HealthXpBarLength, 9), XpBarOverlay);
GUI.DrawTexture (new Rect (Screen.width / 4 + 6, Screen.height - 14.5f, LevellingSystem.curHealth, 9), HealthBarOverlay);
}
What is actually happening, (I think) is that my health bars (both the current health and experience bar) are showing the actual hit points of my character, and not the percentages.
I need the health bar to be displayed as the full 746 pixels in width, and the experience bar should be starting at zero and building up as I gain experience.
Is there anyone who could please help me out with this?
Below is an example of one of my other bars that currently work.
percentOfStrengthXp = curStrengthXp / maxStrengthXp;
StrengthXpBarLength = percentOfStrengthXp * 200;
And here is the GUI code for the working experience bar.
GUI.DrawTexture (new Rect (Screen.width - 202, Screen.height - 234, LevellingSystem.StrengthXpBarLength, 9), XpBarOverlay);
Any help would be GREATLY appreciated! :)
Removed "[solved]" from your topic title. If an answer helps you with your problem, please mark it as the accepted answer.
$$anonymous$$y accepted answer is under moderation.
Answer by OfficialCoatsee · Apr 03, 2014 at 04:18 AM
Thank you, I figured it out, I had simply mixed up my experience with an attack cool down, same with my health. I knew it was such a stupid thing!
Your answer
Follow this Question
Related Questions
Expecting ) found = 1 Answer
If Enemy Health (< 10) then Exp (+10)? 1 Answer
How to get Var from a obj 1 Answer
hitpoints problem 1 Answer