How to get scripts to communicate with each other properly

So, I have these two scripts that communicate properly, except for one thing. The code should make the player withstand 3 hits before loading the losing scene. But the debug.log only prints out hit once before going to the losing screen. And I also have one more problem with script 2. I don’t know how to get the code to wait the proper amount of time before making the zombie attack again. Thanks.

Script 1:

public var totalHealth = 100;
public var damage = 25;

function Update (){
    if (totalHealth <= 0)
        Application.LoadLevel(1);
}

Script 2:

var zhealth = 5;
var zspeed = 5;
var attackTimer = 1;
var attackRange = 1.5;
var zdead = false;
var target : Transform;
var zTransform : Transform;
var healthPlayer : healthPlayer;
var zombie : GameObject;


function Update (){
    if (zdead==true)
        Destroy(zombie);

    if (zhealth<=0)
        zdead = true;

    transform.Translate(Vector3.forward*zspeed*Time.deltaTime);
    transform.LookAt(target);

    var distance = (target.position - zTransform.position).magnitude;
    if(distance < attackRange && Time.time > attackTimer){
        healthPlayer.totalHealth -= healthPlayer.damage;
        Debug.Log ("Hit");
    }
}

The Debug is probably printed 4 times and you have the collapse button pressed. To delay the hits, update the var attackTimer by adding +1, or +2 or whatever the delay is.

Be careful when you name the var with the name of the type (var healthPlayer : healthPlayer). I don’t know what the compiler make of it and it’s making the life of people reading you harder.

Less important but still, when comparing distance you should always compare sqrMagnitude to spare the sqrt. That implies to use the square of attackRange, calculate it at start.