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");
}
}