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 oliver-jones · Dec 08, 2010 at 05:51 PM · transformplaneprogress-barpercentagehealth

Health Bar To Change Size

Right,

I'm sure this is simple enough. Basically, I have a plane above my enemy that is green. What I would like to do, is to decrease the size of the plane according to the variable 'Health' as well as change through the typical health colours (green, yellow, orange, red ...).

Here is my HealthBar Script so far:

var HealthBar : Transform; var Health = 0; private var PercentHealth = int;

function Update() { print(Health); }

This is what I reckon:

The Var Health does not start at 100 (thus cannot be a percentage). EG: an enemy might spawn with a lower hit point, like 40. Meaning their health is 40, but I need to convert this into 100% (Percenthealth) and decrease the plane according to the percentage.

So whatever the health STARTS at (eg: 40), will be 100% Health

I hope that makes scene, I think I have over complicated the situation.

Cheers

Comment
Add comment · Show 1
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 Proclyon · Dec 08, 2010 at 11:37 PM 1
Share

100% of 3.14 = 3.14. A variable does not require to be 100 at 100% to be able to be described with a percentage. per / cent = per / 100 in words. Any size of pie chopped in 100 pieces , big or small.

1 Reply

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

Answer by oliver-jones · Dec 10, 2010 at 12:44 AM

Figured it out:

var HealthBar : Transform; private var MaxHealth : float = 100; private var MaxBar : float = 0.2; var Health : float = 10;

function Update() { // --- Change Size Of Bar --- \\ transform.localScale.x = (MaxBar) * (Health/MaxHealth);

 // --- Change Colour Of Bar --- \\
 if(transform.localScale.x == 0.2)
 {
     transform.renderer.material.color = Color.green;
 }
 if(transform.localScale.x <= 0.15)
 {
     transform.renderer.material.color = Color.yellow;
 }
 if(transform.localScale.x <= 0.05)
 {
     transform.renderer.material.color = Color.red;
 }

}

(PS - No need to remind me - I will tick this answer correct, but I have to wait 48 hours!)

Comment
Add comment · Show 1 · 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 AtomicMarine · Jan 07, 2011 at 01:49 AM 0
Share

helped me out, was helpful thanks :)

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

No one has followed this question yet.

Related Questions

Progression height affected by the width ? why 1 Answer

Health bar by percentage? (not drawing a box) 4 Answers

How to access objects attached to other objects 1 Answer

Call a function based on percentage of health (int) 2 Answers

How would you make an energy bar, loading progress bar, health meter, or other visual gradually fill up? 6 Answers


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