So I have a script attached to a grenade. the grenade has a trigger and a collider attached, I have programmed it so that when the collider touches something it runs an explode function.
The enemies all have a function LooseHealth in a script (EnemyHealthScript) , I am trying to make it so that all enemies within the tigger run the function LooseHealth(100) but I am have trouble. Right now my code for this is:
function OnTriggerStay (collision : Collider) {
if (collision.gameObject.tag == "enemy" && canExplode == true){
collision.EnemyHealthScript.LooseHealth(100);
Destroy (gameObject);
}
}
This doesnt work, I have also tried using
collision.GetComponent(EnemyHealthScript).LooseHealth(100);
but that does not work either.
Do you have any advice on how to make it work?