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…

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: Unity3D Tutorial #71 [ Floating Health Bars ] - YouTube

var HealthBar1 : GameObject;
var HealthBar2 : GameObject;
var HealthBar3 : GameObject;
var Health = 3;

function Update(){

if(Health < 1){

if(Health == 1){ = true; = false; = false;

if(Health == 2){ = true; = true; = false;

if(Health == 3){ = true; = true; = 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