Enemy Tag in Range

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);
					//eh.audio.PlayOneShot(eh.Hit, 1.0f);

if it does not run at all than there is something wrong with if statement. try pushing in some print() statements inbetween the lines see which parts of the code is not accessible.

btw, I’d suppose using an enumerator for your if statement, its more ‘professional’

protected enum State {idle, fighting, walking, doingsomething}

// the state your character is in at the moment:
protected State currentState;

if(currentState == State.fighting){
//kill everyone and moonwalk in a slow motion
//on an exploding background