variable help

heres my script

var bullet : Rigidbody;
var health = 3;
var enemy : GameObject;

function OnCollisionEnter(bullet : Collision){
var health =- 1;
}

function Update(){
if (health == 0);
Destroy (enemy);
}

i didnt know what to put for the variable near the end to destroy the enemy when its out of health so i just tried random stuff and found that this combination came up with no errors, except the cube is destroyed at the start of the game, i tried

Destroy (enemy,3);

and that just destroyed the enemy 3 seconds after the start of the game

help plz.

Hi sam11x, sorry, I’m not sure to have understand your question very well…Do you say that the enemy is destroied at the beginning of the execution? In that case, I think that

if (health == 0);

is wrong. To perform the “Destroy (enemy);” instruction inside the “if” statement you have to delete the “;” at the end of that line. So:

function Update(){
if (health == 0)
Destroy (enemy);
}

Let me know.

The correct usage for an if statement is:

if(health ==0)
{
destroy (enemy);
}

such a simple mistake :).

Also, i would change “health == 0” to “health <=0”. This will solve a future bug that occurs when the enemies health is below 0, which would become a problem if, for example, there was a different bullet that inflicted 5 damage ;).