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
1
Question by oliver-jones · Dec 13, 2010 at 04:47 PM · cameraguifloatlookathealthbar

How To Make A Floating Health Bar

Hello,

I have a load of initiated enemies that come onto the scene. They all have planes above their heads that is green, and when health is deducted, the plane gets smaller whilst changing colour.

How do I make the plane always face the camera 'so it appears like a GUI', and not rotate with the enemy?

(The health bar plane is a child of the enemy)

Unless you have any other ideas.

Here is my health bar script:

var HealthBar : Transform; var MaxHealth : float; var MaxBar : float; var Health : float; var m_Camera : Camera;

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;
 }

}

Thanks, Ollie

Comment
Add comment
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

1 Reply

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

Answer by Bampf · Dec 13, 2010 at 05:10 PM

Keeping a plane rotated to face the camera is called "billboarding".

http://answers.unity3d.com/questions/13611/how-to-create-billboarding-planes

Comment
Add comment · Show 2 · 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 oliver-jones · Dec 13, 2010 at 07:25 PM 0
Share

Okay, Its getting there, but because the healthbar is a child of the enemy, the position goes a bit funny every time the enemy rotates - How do I get it so that the health bar is always on top of the enemy?

http://www.youtube.com/watch?v=dC30FSgsoms

avatar image Bampf · Dec 14, 2010 at 03:24 AM 0
Share

A few ways you could do it. 1. You could have the enemy and the bar both be children of an empty child object. You'd translate the parent to move both, but only rotate the enemy. 2. After the rotation of the enemy, rotate the billboard only backwards the same amount. This should position it back where it was, if you use the right origin. 3. Ins$$anonymous$$d of making the billboard a child of the enemy, have it be a separate, unrelated object with a script on it to make it follow the enemy around.

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

How to make a camera's background be another camera's veiw 1 Answer

How do you force a player to look at something? 4 Answers

resetting the my default value for camera field of view 1 Answer

Having a plane at exactly the far clip of a camera 1 Answer

GUI ammo counter not linked to player 0 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