• 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 Ekta-Mehta-D · Oct 01, 2013 at 12:43 PM · enemyhealthbarhealth

Healthbar above enemy : 2d

hello everyone..

I want to add health bar for each enemy.. but i have never implement health bar functionality.. So i want some simple script and idea to create health bar.

In my scene i want my enemy to die after shooting 3 times.. But how to create health bar on the top of the enemy and how will i change health bar color?

Please help me and suggest me some simple ideas to manage health for each enemy.

Thanks for your help and support..

Comment
Add comment · Show 4
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 Ekta-Mehta-D · Oct 01, 2013 at 01:17 PM 0
Share
avatar image mattssonon · Oct 01, 2013 at 01:50 PM 0
Share
avatar image Ekta-Mehta-D · Oct 04, 2013 at 05:51 AM 0
Share
avatar image Artifactx · Oct 18, 2014 at 05:45 AM 0
Share

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by TargonStudios · Oct 01, 2013 at 01:05 PM

 var HealthBar1 : GameObject;
 var HealthBar2 : GameObject;
 var HealthBar3 : GameObject;
 var Health = 3;
 
 function Update(){

 if(Health < 1){
 Destroy(gameObject)
 }
 
 if(Health == 1){
 HealthBar1.active = true;
 HealthBar2.active = false;
 HealthBar3.active = false;
 
 }
 if(Health == 2){
 HealthBar1.active = true;
 HealthBar2.active = true;
 HealthBar3.active = false;
 
 }
 if(Health == 3){
 HealthBar1.active = true;
 HealthBar2.active = true;
 HealthBar3.active = true;
 
 }
 }

Note- T$$anonymous$$s is not a GUI Health bar, its actual cubes/GameObjects.

T$$anonymous$$s is just the health bar, I made it for an older game. Make 3 "HealthBar's" side by side, labile them 1 from 3 (I textured them green to represent health, And I put a red background be$$anonymous$$nd the green health bars. I also put them over the enemy) And then assign the Health Bars to the script. Now all you have to do is make a damage script in it. Hope t$$anonymous$$s helps

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 Lovrenc · Oct 01, 2013 at 01:06 PM 1
Share
avatar image TargonStudios · Oct 01, 2013 at 01:11 PM 0
Share
avatar image Lovrenc · Oct 01, 2013 at 01:49 PM 0
Share
avatar image TargonStudios · Oct 01, 2013 at 02:05 PM 0
Share
avatar image s_guy · Oct 04, 2013 at 07:10 AM 0
Share
Show more comments
avatar image
0

Answer by mattssonon · Oct 01, 2013 at 01:06 PM

T$$anonymous$$s is a very broad question, there are plenty of existing examples and tutorials out there on how to do t$$anonymous$$s. I would suggest you follow t$$anonymous$$s guide: http://www.youtube.com/watch?v=rNeIj1Ll4_k

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 Ekta-Mehta-D · Oct 01, 2013 at 01:15 PM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

How to create Enemy Health Bar ? 4 Answers

How can I do health bar follows enemy? 1 Answer

Rect Following Object : Unity3d 1 Answer

Health below zero but shows negative numbers 1 Answer

A node in a childnode? 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