- Home /
how do i kill multiple enemies?
I have a script for my enemy health and a script to do damage to him. However if I have multiple enemies the bullets will do damage and kill only one of them and just pass right through the rest of them. Please tell me what I am doing wrong. here is the bullet damage script followed by the health script.
var damage: float = 5.0;
var ApplyDamage : Drone_health;
function OnTriggerEnter (other : Collider) {
if(other.gameObject.CompareTag("Enemy"))
print("ow!");
ApplyDamage(damage);
}
@script AddComponentMenu("Environment Props/DamageTrigger")
Health script
var health: float = 10.0;
function ApplyDamage(damage: float){
health -= damage;
//check health and call Die if need to
if(health <= 0){
health = 0; //for GUI
Die();
}
}
function Die(){
print("dead!");
Destroy (gameObject);
}
How are you setting var ApplyDamage : Drone_health;
? Usually you would set the target of a trigger action inside OnTriggerEnter (other : Collider)
using the collider.
what do you mean "How are you setting var ApplyDamage : Drone_health;? " I am not sure I understand what you are asking? could you please explain it to me in terms I can understand.
What is Drone_health
? A script? If so, please show some code from it.
Hi @twinmoon,
I really don't understand what the info you give. You say "here is the bullet damage script followed by the health script", so I expect to find 2 scripts (1 for Damage and 1 for Health), but you only provide 1 script containing 30 lines!
Additionally, in line 2 you declare the variable ApplyDamage of type Drone_health and you don't supply the code for the Drone_health script either (what@mattssonon is also asking). I mean it's not like ApplyDamage is of a known type like int or string, so how can we know what it stands for if you don't give the relevant code for it?
Last but not least, you are not clear enough about which game object each of these scripts is attached to. Do you actually have bullet objects with a script flying around doing damage? And if so, are these bullet objects actually necessary for the game? Because I would personally use raycasting to effect the damage of a bullet on an enemy.
We are all volunteers trying to help, but if you don't give enough information it's like you don't want to be helped.
@pako - I think the health script starts where he wrote "Health script" on line 12.