- Home /
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..
I'd suggest doing a Google search, there a lot of tutorials out there.
thanks everyone. i have solved and created healthbar using gui texture..
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
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
I think this is really poor design and does more harm than good when someone is trying to learn proper coding.
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.
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.
@Lovrenc best form when offering critique would be to lead by example.
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
Your answer
Follow this Question
Related Questions
How to create Enemy Health Bar ? 4 Answers
Rect Following Object : Unity3d 1 Answer
Health below zero but shows negative numbers 1 Answer
Enemy Health Problem 2 Answers
Enemy Health Help 1 Answer