FPC health bar

Im putting zombies in my game, but i dont know how to make them inflict damage on me.Also how would i put a health bar on me screen that goes down every time the zombie hit me. If anyone can write me a script or refer me to a tutorial that would be good :slight_smile:

[Try this][1] [1]: http://lmgtfy.com/?q=unity+healthbar+tutorial

–

snarky comment related to relative screen space occupied by related questions and links to Answers FAQ/tutorials

–

Lockstep beat me to it! Haha I was right about to post the same thing.

–

From now on lmgtfy is the official answer to ignorant questions.

–

1 Answer

1

create a class for player health

for example

var maxHealth:int=150;
var currentHealth:int;

function Awake()
{
	currentHealth=maxHealth;
}

function Update()
{
	if(currentHealth>maxHealth)
		currentHealth=maxHealth;
	if(currentHealth<0)
		currentHealth=0;
}
function ApplyDamage(damage:int)
{
	currentHealth-=damage*Time.deltaTime * 1;
	if(currentHealth<=0)
	{
		Die();
		Debug.Log("You Are Dead");
	}
 
    
	
}

function Die()
{
   //Die code here
}

function OnGUI()
{
//set position on screen, just an example
	var positionHUDY=Screen.height-68;
	var positionHUDX=Screen.width-260;
	
		//Draw the healthbar
		GUI.Box(Rect(positionHUDX,positionHUDY,256,64),currentHealth.ToString());
		
	
}

then you have to call apply damage function and send the damage amount