Health/Damage Script won't work :(

Hi,

i’ve wrote two small scripts for health and damage in my FPS but the code doesn’t work.
Can someone help me ?

Code for the Player :

static var health : int = 10;

function Update(){

if(health == 0){

print (“alles geil”);

}
}

Code for the Enemy :

var damage = 10;

function OnTriggerEnter (other : Collider){

if (other.gameObject.tag == “Player”)

HealthPlayer.health -= damage;

}

Thank you

Did you make sure the player has the tag “Player”.

OntriggerEnter also only works if one of them has a rigidbody attached, and both colliders need to have the tag “Is trigger” ticked I believe. If you have 2 objects which both have a collider and rigidbody attached, you’re probably going to want to use OnCollisionEnter

Also you should change your Update function to check if health less than or equal to zero.

Code for the Player :

static var health : int = 10;

function Update(){

if(health == 0){

print (“alles geil”);

}
}

Code for the Enemy :

var damage = 10;

function OnCollisionEnter (Collision : Collider){

if (collision.gameObject.tag == “Player”)

HealthPlayer.health -= damage;

}

So,would that work? (can’t test it right now)

//use:
if(health <= 0){}

// instead of 
if(health == 0){}

And use Code tags when posting code please.