I have this working health script but it only deducts health when there is one zombie in range not when there is multiple of them. I wan it to deduct say 2 when there is two zombies and 10 when theres 10?
using UnityEngine;
using System.Collections;
public class Health : MonoBehaviour {
private float maxHealth = 100f;
public float curHealth = 100f;
private float width = 150f;
private float height = 35f;
public GUITexture HealthBar;
private float time = 0;
private GameObject zombie;
private eHealth damage1;
// Use this for initialization
void Start () {
//Start of Health bar
HealthBar.pixelInset = new Rect(Screen.width/-2.1f, Screen.height/2.25f, width, height);
zombie = GameObject.FindGameObjectWithTag("Zombie");
damage1 = zombie.GetComponent<eHealth> ();
}
float newHealth (float damage){
curHealth = curHealth - damage;
return curHealth;
}
// Update is called once per frame
void Update () {
//Percentage of health
float per;
per = curHealth/maxHealth;
//New Bar Called when loss of health
HealthBar.pixelInset = new Rect(Screen.width/-2.1f, Screen.height/2.25f,width * per, height);
time += Time.deltaTime;
float dis = Vector3.Distance (zombie.transform.position, transform.position);
if (time >= 2f) {
time = 0f;
if (dis<=2f)
newHealth (damage1.damage);
}
if (curHealth >= maxHealth)
curHealth = maxHealth;
if (curHealth <= 0)
curHealth = 0;
if (curHealth <= 0)
Destroy (gameObject);
}
}