[JAVA]DAMAGE

HELP
i have two scripts
but the script has been crashed
if i attack with my sword in the ennemy
his live dont less
that is the scripts
name=Aidan

#pragma strict
var diff:int;
static var ailife:int;

function Start () {
ailife=1;
}

function Update () {
            if(diff==1){
            ailife=10;
            if(ailife<1){
            Attributes.xp+=5;
            Dead();
            }
            }
        if(diff==2){
        ailife=40;
        if(ailife<1){
        Attributes.xp+=20;
        Dead();
        }
        }
            if(ailife==3){
            ailife=60;
            if(ailife<1){
            Attributes.xp+=33;
            Dead();
            }
            }



}
function Dead(){
    Destroy (gameObject);
}

the other
name=DanoNoAi

#pragma strict
function OnCollisionEnter(Collider:Collision){
    if(Collider.gameObject.tag=="aii"){
        AIdan.ailife-=10;
    }
}

update is called every frame, you are resetting the life amount to full, every frame.

All of the code where you set the initial life value needs to be in the Start() function.

static variables are class level and all instances of the class use the same value. You don’t want to use a static value for the life of a unit in your game, otherwise hurting one of them will hurt all of them.