I’ve got several clone NPCs and have this function in them:
function applyDamage(dam : int)
{
health = (health - dam);
Debug.Log("health--");
if (health <= 0)
{
Destroy(gameObject);
}
}
The projectile class has this when hit:
for (var hit : Collider in colliders) {
if (!hit)
continue;
if (hit.gameObject.name == "Enemy_L1"){
hit.gameObject.SendMessage("applyDamage", 10);
}
gameObject.Destroy(gameObject);
My problem is that when one NPC is hit with the projectile, all of them die. How do i just destroy one of them?