Simple collision code problems.

I have no idea why this seemingly simple bit of code is not working. Any help would be appreciated.

function OnTriggerEnter (collision : Collider) {
if (collision.gameObject.name == "Enemy1(Clone)" && canExplode == true){ 
     collision.GetComponent(EnemyHealthScript).LooseHealth(30);
     Destroy (gameObject);

}
}

1 Answer

1

Are you creating a collider or a trigger?

If you’re using OnTriggerEnter your collider must be marked as a trigger in the editor.
If you want to do actual collision testing, and your item is not a trigger, use OnCollisionEnter

Im using a trigger, the log says there is an error in the line collision.GetComponent(EnemyHealthScript).LooseHealth(30); but I dont see it.