how i do this in javascript?

hello guys

well, i created a script in JS about the life of the enemy. what is this:

#pragma strict

var muerto : boolean = false;
var vidaE : float = 100;

function Update () {

if (vidaE >= 100) {
vidaE = 100;
}

if (vidaE <= 0) {
muerto = true;

}

if(muerto == true){
Destroy (this.gameObject, 2);
}
                                                                       
}

my doubt is the following:

how can do what the life of the enemy down with a animation of the player? because i know what the logic would put a function OnTriggerEnter (other : Collider) and his condition in the code. but happend what i want what when my Player use a animation of his animation´s tree, the life of enemy down. example: the animation of punch

i try with this, but i don´t know if it’s okay :

var : AnimationClip : Boolean = false;

the explication of that, is what when i press the key mouse0, the animation punch, what is a boolean, is activated. so, when she pass to true, in this code the script would know that and would do what the life down. but, don´t know how insert that here u.u

i wait his help guys, thank you and good night :slight_smile:

if I’m reading this right I think you will want to have a “Damage” function in your health script so that other scripts can reduce the health.

Something similar to the “TakeDamage” function used in this tutorial

As for how to call that function when the punch animation is executed you might want to look at the “animation events”.
https://docs.unity3d.com/Manual/animeditor-AnimationEvents.html

either to call a function at the full extent of the punch to check if there is a collider and call the damage function on that collided object, or to activate and then deactivate a trigger so that OnTrigger#### function can be used. (not sure which you were after on that)