I've got a problem. I have two scripts, an enemy script and a bullet script. On the bullet script is this function to deduct health from the enemy inside an `OnCollisionEnter`:
if (collider.gameObject.CompareTag ("Enemy")) {
collider.BroadcastMessage("ApplyDamage", 25.0);
}
I have this script on the enemy to take damage:
function ApplyDamage(damage : float) {
hitPoints -= damage;
if (hitPoints <= 0.0) {
Destroy (gameObject);
}
}
Now, this won't work. Any ideas? Thanks a lot.
EDIT - some additional info:
The enemy is a simple box at the moment with a character controller. It has a gun as a child, without any collider. I have an AI script and a damage reciever script attached to it. When I send it a message to do `ApplyDamage` from my bullet, nothing happens. The function isn't called. I'm frustrated.
EDIT - some more additional info:
My script works the first time, but then every additional time, it doen't. Almost like it's destroying itself after the first hit. Any more ideas? I've spent a day and a half on this. And yes, I am logging a collision, because my bullet explodes on contact. And, he follows me the first time until I shoot him. Then, he stops moving as well.