• 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

Is there any other tutorial , example available?

avatar image mattssonon · Oct 01, 2013 at 01:50 PM 0
Share

I'd suggest doing a Google search, there a lot of tutorials out there.

avatar image Ekta-Mehta-D · Oct 04, 2013 at 05:51 AM 0
Share

thanks everyone. i have solved and created healthbar using gui texture..

avatar image Artifactx · Oct 18, 2014 at 05:45 AM 0
Share

Well here is a tutorial about making a healthbar with the new UI from Unity 4.6. You can use the excact same bar by changing the rendering mode on the Canvas from world to Free, and then place a bar on each enemy: Health bar tutorial

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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

This is a very broad question, there are plenty of existing examples and tutorials out there on how to do this. I would suggest you follow this 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

hmm.. i found it some what complex..But thanks..

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- This is not a GUI Health bar, its actual cubes/GameObjects.

This 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 behind 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 this 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

I think this is really poor design and does more harm than good when someone is trying to learn proper coding.

avatar image TargonStudios · Oct 01, 2013 at 01:11 PM 0
Share

This technique has personally worked perfectly fine for me for every game I made. I know its not the best way to do it, but it works so I thought I would try and help.

avatar image Lovrenc · Oct 01, 2013 at 01:49 PM 0
Share

What if enemy has 3000 hitpoints?

avatar image TargonStudios · Oct 01, 2013 at 02:05 PM 0
Share

In this case it doesn't, And that's why I posted this, But If so I would Assign every bar to represent 300-500 damage maybe. But that's not how I use this health bar Script, I have a defence system. The higher the Defence I set it to, The less damage it gets taken off. Better enemy's have better defences.

avatar image s_guy · Oct 04, 2013 at 07:10 AM 0
Share

@Lovrenc best form when offering critique would be to lead by example.

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.

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

Health below zero but shows negative numbers 1 Answer

Enemy Health Problem 2 Answers

Enemy Health Help 1 Answer

Instantiate with healthbar dont work correctly 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