"Unique" enemy problem (health, animations, etc)

I have an enemy prefab, with an enemyAI script attached. The prefab is a rigged and animated character (using animator)

My enemy has 5 hp. I drag two prefabs into the scene and play - If I shoot the first enemy, which is closest to me, both enemies play the “hit” animation. Also, both enemies die at the same time, even though I’m only attacking the closest.

If I step into the first enemies trigger, both enemies begin attacking, even though the second enemy is far away.

This is my enemyAI script

using UnityEngine;
using System.Collections;

public class EnemyAI : MonoBehaviour 
{
	private Animator anim;

	private Transform stinger;

	public GameObject ParticlePrefab;
	public GameObject health;
	public GameObject instantiated;

	public Rigidbody stingerPrefab;
	Rigidbody clone;

	private float bulletSpeed = 1500.0f;

	public bool step = true;
	public bool playerInRange = false;
	public int enemyHealth = 5;



	void Start () 
	{
		stinger = GameObject.Find("stingerPos").transform;
		anim = GetComponentInChildren<Animator>();
	}

	void Update () 
	{
		playerInRange = PlayerMovement.playerInRange;
		anim.SetBool ("Detected", playerInRange);
		anim.SetBool ("enemyHit", destroyBullet.enemyHit);

		if(destroyBullet.enemyHit)
			--enemyHealth;

		if(playerInRange && step)
			Attack();
		 
		if(enemyHealth <= 0)
		{
			Destroy (gameObject);
			instantiated = (GameObject)Instantiate(ParticlePrefab, transform.position, transform.localRotation);
			if(PlayerMovement.playerHealth < 3)
			instantiated = (GameObject)Instantiate(health, transform.position, transform.localRotation);
			
		}
	}

	IEnumerator AttackWait()
	{
		step = false;
		yield return new WaitForSeconds(0.75f);
		step = true;
	}

	void Attack()
	{
		int attackProb = Random.Range(0,7);
		if(attackProb == 3 || attackProb == 1)
		{
			if(!destroyBullet.enemyHit)
			{
				clone = Instantiate(stingerPrefab, stinger.position, stinger.localRotation) as Rigidbody;
				clone.AddForce(transform.forward * bulletSpeed);
				StartCoroutine(AttackWait());
			}
		}
		else
		{
			StartCoroutine(AttackWait());
		}
	}

}

How can I make enemies unique? I would like to have many enemies in the scene, not just 2

Any ideas on what I’m doing wrong? Thanks

Looks like your EnemyAI scripts are getting the playerInRange and destroyBullet.enemyHit variables from the same object.

Seems like you have a variable playerInRange on your PlayerMovement script - and then you check the value of that in the enemy script. You should determine if your player is in range on the enemy script, because now, when you set playerInRange to true on your player ALL enemies will have PlayerMovement.playerInRange as true (this is why both enemies begin attacking even when you only step in one trigger).

Similar problem with your bullet: it looks like you have every enemy script asking a bullet if it’s hit anything, then have all of them take damage when it has. You should make a method in your bullet script that determines what enemy it’s hit and then call a TakeDamage method on that enemy’s script.