All my enemies are attacking simultaneously. I wanted each spawned prefab enemy to act independently. Please Help!

public class MovementLeft : MonoBehaviour
{

float dirX;

[SerializeField]

Rigidbody2D rb;

public static bool isAttacking = false;

Animator anim;

float speed = 1f;
Vector3 localScale;


void Start ()
{
    localScale = transform.localScale;
    rb = GetComponent<Rigidbody2D> ();
    dirX = 1f;
    anim = GetComponent<Animator> ();
}
void Update()
{
    
    if (transform.position.x < -9f)
        dirX = 1f;
    else if (transform.position.x >9f)
        dirX = 1f;
    if (isAttacking)
        anim.SetBool ("isAttacking", true);
    else
    {
            anim.SetBool ("isAttacking", false);
    }
    
}
void FixedUpdate()
{
    if (!isAttacking)
        rb.velocity = new Vector2(dirX * speed, rb.velocity.y);
    else
    {
        rb.velocity = Vector2.zero;
    }
        
}

}

public class AttackKnight : MonoBehaviour

{

    public MovementLeft movementleft;
   
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.name.Equals("KnightRight"))
        {
            movementleft.isAttacking = true;
        }
    }

    void OnTriggerExit2D(Collider2D col)
    {
        if (col.gameObject.name.Equals("KnightRight"))
        {
            movementleft.isAttacking = false;
        }
    }
}

When movementleft.isAttacking is equal to true, it plays an attack animation, by setting a bool in the animator to true. However, this animation is linked to all of your enemies, causing them to all play the same animation clip at the same time, im guessing. A way to solve this is by getting the name or identity of the enemy that is near the player, for example, and getting the animator component of that animation and only setting the bool to true for that specific enemy. Let me know if this is the case. I dont fully understand the context of your scripts and animator components etc.

Thank you for your response. What I wanted is, even if you have 10 enemies close to the KnightRight they would be doing their own attacking animation and doing damage separately. you would click on a button carrying a prefab, which I already have, and one enemy would appear and get close to KnightRight and attack, then, if you click on the button again, another enemy would appear and get close to KnightRight and attack. If I remove the static I get a NullReferenceException: Object reference not set to an instance of an object on the movementleft.isAttacking = true. Thank you again.