Coroutine to WaitForSeconds() on enemy AI causing all instances of AI to pause. Solution?

I have two zombie prefabs instantiated right now, both with the following script in the prefab.

void Update () {
		player = GameObject.FindGameObjectWithTag ("Player");
		allies = GameObject.FindGameObjectsWithTag ("EnemyOther");
		allyCount = allies.Length;

		float distance = Vector3.Distance (transform.position, player.transform.position);
		Debug.DrawRay (new Vector3(transform.position.x, transform.position.y  + 1, transform.position.z), (player.transform.position - new Vector3(transform.position.x, transform.position.y + 1, transform.position.z)),  Color.red);

		if (Physics.Raycast (new Vector3 (transform.position.x, transform.position.y + 1, transform.position.z), (player.transform.position - new Vector3(transform.position.x, transform.position.y + 1, transform.position.z)), out hit, maxRange, 9));
		{

			/*for (int i = 0; i < allyCount; i++) 
			{
				if (Vector3.Distance (allies*.transform.position, transform.position) < maxRange && distance >= 1.7 && !attacking)*
  •  		{*
    

_ bool pursuing = allies*.GetComponent ().pursuing;*_

* lastKnownPosition = player.transform.position;*

* transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));*
_ transform.position += transform.forward * moveSpeed * Time.deltaTime;
* animation.CrossFade(“run”);*
* }*
}*/_

* if(hit.transform.tag == “PlayerOther” && distance >= 1.7 && !attacking)*
* { *
* lastKnownPosition = player.transform.position;*

* transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));*
_ transform.position += transform.forward * moveSpeed * Time.deltaTime;_
* animation.CrossFade(“run”);*

* }*

* if(hit.transform.tag == “PlayerOther” && distance <= 1.8 && !attacking)*
* {*
* attacking = true;*
* StartCoroutine (AttackAnimation());*
* }*

* if (hit.transform.tag != “PlayerOther”)*
* {*
* transform.LookAt (lastKnownPosition);*
_ transform.position += transform.forward * moveSpeed * Time.deltaTime;_
* animation.CrossFade (“run”);*

* }*
* }*
* }*

* IEnumerator AttackAnimation()*
* {*
* animation.CrossFade (“attack1”);*
* yield return new WaitForSeconds(animation[“attack1”].length);*
* PlayerStats.Health = PlayerStats.Health - 10;*
* attacking = false;*

* }*
}

When one zombie gets close enough to attack, all zombies stop in their tracks as well rather than only the one who is close enough. This is my first time using a Coroutine, can I get some pointers? Thanks

Is it possible that you have declared “attacking” as static variable? In that case it is shared across all instances since there is only one “attacking” variable, no matter how many instances you create. Variables which should be per instance must not be static.

Since you didn’t include the declaration of “attacking” it’s just a guess. However if you have strange interaction between different instances that’s usually caused by some hidden global state (like static variables).