Problem killing enemy with multiple enemies in scene.

Having a problem when I shoot an enemy when more than one are in scene, It works okay with one enemy at a time but that’s not my intention… not sure where I’ve gone wrong or if I’ve done more than one thing wrong so any help will be appreciated :slight_smile:

A real noob here with very little coding experience besides following some tutorials and trial & error so excuse my spaghetti coding.

Script attached to the zombies:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ZombieHealth : MonoBehaviour
{

public int currentHealth;                       // The current health enemy has.
public int maxHealth = 100;

public AudioClip deathClip;

Animator anim;                                 // Reference to the Animator component.
AudioSource zedAudio;                          // Reference to the AudioSource component.
EnemyAI zedControl;                            //Reference to the AI Controls.
EnemyAttack zedAttack;
bool dying;                                   // Whether is dead.
bool damaged;                                // True when gets damaged.

void Awake()
{
    // Setting up the references.
    anim = GetComponent<Animator>();
    zedAudio = GetComponent<AudioSource>();
    zedControl = GetComponent<EnemyAI>();
    zedAttack = GetComponent<EnemyAttack>();

    // Set the initial health of the enemy.
    currentHealth = maxHealth;
}

void Update()
{

    Dying();
}

void Dying()
{
    // If the enemy has lost all it's health and the death flag hasn't been set yet...
    if (currentHealth <= 0)
    {
        zedAttack.enabled = false;
        zedControl.enabled = false;

        // ... it should die.
        Death();
    }
}

void Death()
{

    anim.SetTrigger("Dead");                // Telling the animator that the enemy is dead.
    zedAudio.clip = deathClip;              //Get the death sound.
    zedAudio.Play();                        //Play death sound.
    Destroy(gameObject, 5f);                //Destroy the corpse.
}

public void TakeDamage(int amount)
{
    // Reduce the current health by the damage amount.
    currentHealth -= amount;

   
}

}

Script attached to the bullets:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour {

public GameObject bullet;         // Reference to bullet Prefab.
GameObject Zombie;                // Reference to Zombie Prefab.
ZombieHealth zedScript;           // Reference to Zombie HealthScript.
ZombieHealth zedHealth;           // Reference to Zombie Health.
ZombieHealth currentHealth;       
public int attackDamage = 10;     // Reference to bullet damage.

// Use this for initialization
void Start ()
{
    Zombie = GameObject.FindGameObjectWithTag("Enemy");
    zedHealth = Zombie.GetComponent<ZombieHealth>();
    currentHealth = Zombie.GetComponent<ZombieHealth>();
    StartCoroutine(LetMeSpawn());

}

// Update is called once per frame
void Update ()
{
    

    
   
}

public void Attack()
{//
    zedScript = Zombie.gameObject.GetComponent<ZombieHealth>();

    // If the zed has health to lose...
    if (zedScript && zedHealth.currentHealth > 0)
    {

        //... damage the zed.
        zedScript.TakeDamage(attackDamage);
    }

}

//Function to disable then enable the bullet's collider.
IEnumerator LetMeSpawn()
{
    bullet.GetComponent<PolygonCollider2D>().enabled = false;
    yield return new WaitForSeconds(0.1f);
    bullet.GetComponent<PolygonCollider2D>().enabled = true;

}

void OnCollisionEnter2D(Collision2D col)
{
    if (col.gameObject.tag == "Enemy")
    {
        
        Attack();
        Debug.Log("Hit Target");
        Destroy(gameObject, 0.01f);
    }

    
}

private void OnCollisionExit2D(Collision2D other)
{

}

}

I believe I may have fixed the problem…
The new bullet code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour {

public GameObject bullet;         // Reference to bullet Prefab.
public int attackDamage = 10;     // Reference to bullet damage.

// Use this for initialization
void Start ()
{

    StartCoroutine(LetMeSpawn());

}

// Update is called once per frame
void Update ()
{
}

//Function to disable then enable the bullet's collider.
IEnumerator LetMeSpawn()
{
    bullet.GetComponent<PolygonCollider2D>().enabled = false;
    yield return new WaitForSeconds(0.01f);
    bullet.GetComponent<PolygonCollider2D>().enabled = true;

}

void OnCollisionEnter2D(Collision2D col)
{
    if (col.gameObject.tag == "Enemy")
    {
        col.gameObject.GetComponent<ZombieHealth>().TakeDamage(attackDamage);
        Debug.Log("Hit Target");
        Destroy(gameObject);
    }

}

}