Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by OfficialCoatsee · Mar 23, 2014 at 04:36 PM · experiencehitpointshealth

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! :)

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lo0NuhtiK · Apr 03, 2014 at 04:00 AM 0
Share

Removed "[solved]" from your topic title. If an answer helps you with your problem, please mark it as the accepted answer.

avatar image OfficialCoatsee · Apr 03, 2014 at 04:17 AM 0
Share

$$anonymous$$y accepted answer is under moderation.

1 Reply

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hello, i am trying to implement Hitpoints UI for my player, so that everytime my player looses a hitpoint the value should decrement by 1. I have done creating the panel with score. Hereby attached the health script. Please Help 0 Answers

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges