Script help! if var = 0

function OnCollisionEnter(collision : Collision) {
	var EmemyHP = 3;
	if (other.gameObject.CompareTag ("PlayerProjectile"));
		--EnemyHP;
	if (EnemyHP = 0);
		Destroy (gameObject);		
}

What’s wrong with line 5? I keep getting “unexpected token : 0” and "expecting ) found ‘=’ "

in if statements, you have to do ==, <=, or >=, or >>/<<

Thanks. Current:

function OnCollisionEnter(collision : Collision) {
	var EnemyHP = 3;
	var Nada = 0;
	if (gameObject.CompareTag ("PlayerProjectile"));
		--EnemyHP;
	if (EnemyHP == Nada);
		Destroy (gameObject);		
}

This is supposed to give the enemy 3 hitpoints. However, shooting it destroys the object immediately. Thoughts on that?

EDIT: My tag isn’t working either.

What? No, an if statement just has to be able to evaluate to true or false. Just about everything does, but >> and << are binary operators and you forgot !=.

Anyway.

The whole problem is you mispelled EnemyHP.

You’re setting enemyHP to 3 and nada to zero each time the function is called; there’s no way that enemyHP will ever equal nada. enemyHP needs to be declared outside a function to persist between function calls.

You have a semicolon at the end of both your if statements, so you’re getting “if hp == 0 then nothing”. That’s not how ifs are used:

if ( enemyHP == 0 ) Destroy( gameObject );

Why are you calling it enemyHP anyway? Variables should be named from the perspective of the object they’re attached to. It should be just HP ( or health or hitPoints ), to help prevent confusion later when your scripts become more complex.

oh, sorry, i forgot that one, and i forgot it was only < and >. sorry

var EnemyHP = 3;
function OnTriggerEnter(Projectile1 : Collider) {
	if (gameObject.CompareTag ("PlayerProjectile"))
		--EnemyHP;
	if (EnemyHP == 0); 
		Destroy (gameObject);
				
}

Still not working.

you have a semicolon after your if statement:
if (EnemyHP == 0);

you want
if (EnemyHP == 0)
Destroy (gameObject);

or even safer to always use {}
if (EnemyHP == 0) {
Destroy (gameObject);
}