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 SrBilyon · Jul 03, 2012 at 07:09 AM · editorinspectorhealthbarprogressprogressbar

Health Bar in Custom Editor/Inspector

I've been learning Editor scripting for the last few hours and kinda have the hang of it. Right now, I'm trying to make healthbar using a [ProgressBar][1]. I have a health and max health variable is exposed in the inspector, and I can't seem to figure out how use ProgressBar in a way to make the bar work properly.

I know that ProgressBar's value has to be between 0 and 1, so I tried some math, but wasn't successful.

 ProgressBar ( (((health.intValue + maxHealth.intValue) / 2) /100.0), "health");

The above code snippet works well when the maxHealth value = 100. So I thought, why not change the "100.0" to maxHealth.inValue?

Well, The bar is filled when health and maxHealth is equal, but if I decrease health, it appears that ProgressBar snaps it's own value from 1 right to 0, because the bar becomes completely empty.

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 asafsitner · Jul 03, 2012 at 07:24 AM 0
Share

Um, shouldn't the equation just read health.intValue / maxHealth.intValue? That will give the fraction between 1 to 0 that health is...

avatar image SrBilyon · Jul 03, 2012 at 07:31 AM 0
Share

It seems to snap/round using that formula.

1 Reply

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

Answer by diddykonga · Jul 03, 2012 at 07:19 AM

I think you might just be over complicating this XD

First off the first parameter of ProgressBar is the position, so you might want to try that first.

Then for the value just do:

 health.intValue/maxHealth.intValue

simple as that, if health is 50 and max is 100

 50/100 = 0.5 Correct!


Remember try not to overcomplicate things :)

Comment
Add comment · Show 7 · 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
avatar image SrBilyon · Jul 03, 2012 at 07:25 AM 0
Share

Thanks, I thought I was at first, but it appears that I get the same result. The bar snaps to either empty or full.

avatar image diddykonga · Jul 03, 2012 at 07:32 AM 0
Share

Can you post your code? cause it shouldnt do that 0-o

avatar image SrBilyon · Jul 03, 2012 at 07:32 AM 0
Share

Updated the post.

avatar image diddykonga · Jul 03, 2012 at 07:38 AM 0
Share

$$anonymous$$ind posting what values you have as your health and max health, when it snaps?

avatar image diddykonga · Jul 03, 2012 at 07:45 AM 1
Share

Oh lol just remembered basics of C, you cant divide two ints and get a float value, so you need to make those two floats :)

Show more comments

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

6 People are following this question.

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

Related Questions

Repurposing the inspector graph module 2 Answers

How could I merge 2 components' inspectors through a custom editor? 2 Answers

How can I override the default inspector editor with my own? 3 Answers

How to update objects material on Editor 1 Answer

ReImport in c# of GameObjects only for Scene Objects, not assets? 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