Enemy health drops but not if first enemy lives, how do i change that?

My script works perfectly except, if enemy1 hasnt been “killed”(when health = 0, it dies.) enemy2 cant be attacked. I need to be able to reduce any enemies health when pressing the Attack button and enemy is inside the attackThreshold…

like i said this all works, just i cant kill enemy2 unless enemy1 is dead.
Anyone have any idea what i can do to achieve this?

using UnityScript by the way.

This is my EnemyScript.js

private var enemyMaxHp : float;
private var enemyCurHp : float;
var startingHealth : float = 100.0;
var target : Transform;
var moveSpeed = 10;
var rotationSpeed = 10;
var attackThreshold = 10; //distance in which to attack
var giveUpThreshold = 51; //how close you get before enemy start chase
var attackRepeatTime = 100; //attack delay
private var damage;
private var chasing = false;
var attackTime;
var myTransform : Transform; //current transform data of the enemy
private var distance;
var idle;
myTransform = transform; //cache transform data for easy access/performance

function Awake(){
attackTime = Time.time;
myTransform = transform; //cache transform data for easy access/performance
}

function Start(){
 enemyMaxHp = startingHealth;
 enemyCurHp = startingHealth;
	target = GameObject.FindWithTag("Player").transform; //target the player
}


function Update () {
distance = (target.position - myTransform.position).magnitude;
	if (enemyCurHp > enemyMaxHp){
		enemyCurHp = enemyMaxHp;
	}
	if (enemyCurHp < 0){
		enemyCurHp = 0;
	}
	
	if (enemyCurHp < 1){
	Destroy(gameObject);
	}
			
		if(chasing){
			Chase();
		}
		
		if(distance > giveUpThreshold) { //give up if too far away
			chasing = false;
			idle = true;
			}
		
		if(idle){
			//Idle animation.
		}
		//not currently chasing
		//start chasing if target comes close
		if(distance < giveUpThreshold) {
		chasing = true;
		}
		
		if(distance < attackThreshold){
		Attack();
		}
}

function ApplyEnemyDamage (enemyDamage : float) {
distance = (target.position - myTransform.position).magnitude;
	if(distance < attackThreshold){
    enemyCurHp = enemyCurHp - enemyDamage;
    Debug.Log(enemyCurHp);
    }
}

function Attack () {
chasing = false;
	if(attackTime < Time.time){
	// Calls the function ApplyDamage with a value of 5
	gameObject.FindWithTag("Player").SendMessage ("ApplyDamage", 5.0);
	attackTime = Time.time + attackRepeatTime;
	}
}
function Chase(){
	myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
	myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime; //move to player
}

this is the attack inside of my PlayerScript.js

function PlayerAttack () {
chasing = false;
	if(attackTime < Time.time){
	// Calls the function ApplyDamage with a value of 5
	gameObject.FindWithTag("Enemy").SendMessage ("ApplyEnemyDamage", 10.0);
	attackTime = Time.time + attackRepeatTime;
	}
}

Hello,
I believe that the problems is here:

gameObject.FindWithTag("Enemy").SendMessage ("ApplyEnemyDamage", 10.0);

You are looking for a Game Object with the tag “Enemy”. Since you have more than one, you will have an array of Game Objects with this tag, since Enemy 1 its the first in line, you will always send the damage to him. When he dies, he is deleted, and then this find will return the second enemy. Thats why you need to kill the first one, so this find will find the second enemy.

What you will have to do, its not use the FindWithTag, you will have to make the thing that causes damage to the enemy send the message to the enemy that he is colliding. If you are shooting at them, you will have the bullet to cause damage to the one that took the shot, if its a sword, you will have the sword send the attack to the enemy.
Take care!