Just trying to get this script to work... Checks if animation is playing then any enimes near with the tag "enemy" gets HP taken away
if (animation["attack"].enabled == true) {
GameObject[] enemies = GameObject.FindGameObjectsWithTag("enemy");
foreach(GameObject target in enemies) {
float distance = Vector3.Distance(target.transform.position, transform.position);
if(distance < 4) {
//Rigidbody clone;
//clone = Instantiate(projectile, target.transform.position, target.transform.rotation) as Rigidbody;
AttackandHP eh = (AttackandHP)target.GetComponent ("AttackandHP");
eh.AdjustCurrentHealth (-damage);
SpawnPts();
//eh.audio.PlayOneShot(eh.Hit, 1.0f);
}
}
}
↧