- Home /
Question by
JAIDYZ · Feb 20, 2013 at 09:14 PM ·
health bar
Health Bar problem
I need help with a health bar that displays a colour and the word health and decreases by 10 when hit by rigid body's and when the number gets to zero it freezes the game and says game over restarts please help everything i try fails. The script i have so far is
var healthbar
//if healthbar is 100 and is hit by collider decrese by 10
FunctionOnCollision : 100,0
if Collision decrease by 10 and if hit 0 Destroy "FPSPlayer"
}
Comment
Please format your code, so that people can read it! Do it with th button "101010", :)
Answer by HunterKrech · Feb 20, 2013 at 10:59 PM
something like this ? p.s. might not be perfect, I use c# but right idea i think..
var health: int = 100;
function OnCollisionEnter(collision : Collision){
if(collision.gameobject.name == "//name of thing"){
var health -= 10;
}
}
function Update(){
if(health <= 0 ){
Deastroy(//whatever variable as long as it is an instantiation);
}
}