Damaging a single target

So i’m doing a tower defense game, and when the bullet hits a target and the target dies, all the enemies die. This is my bullet script:
using UnityEngine;

public class Bullet : MonoBehaviour {

private Transform target;

public float speed = 70f;
public int damage = 50;

public float explosionRadius = 0f;
public GameObject ImpactEffet;



public void Seek (Transform _target)
{
    target = _target;
}

void Update ()
{
     if (target == null)
    {
        Destroy(gameObject);
        return;
    }

    Vector3 dir = target.position - transform.position;
    float distancePerFrame = speed * Time.deltaTime;

    if (dir.magnitude <= distancePerFrame)
    {
        HitTarget();
        return;

    }

    transform.Translate(dir.normalized * distancePerFrame, Space.World);
    transform.LookAt(target);

}

void Explode ()
{
   Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius);
    foreach (Collider collider in colliders)
    {
        if (collider.tag == "Enemy")
        {
            Damage(collider.transform);
        }
      
    }

}

void HitTarget()
{

    GameObject effectIns = (GameObject)Instantiate(ImpactEffet, transform.position, transform.rotation);
    Destroy(effectIns, 2f);

    if(explosionRadius > 0f)
    {
        Explode();
    }
    else
    {
        Damage(target);
    }

    Destroy(gameObject);

    
}

void Damage (Transform enemy)
{
    EnemyStats.Health -= damage;
}

void OnDrawGizmosSelected ()
{
    Gizmos.color = Color.red;
    Gizmos.DrawWireSphere(transform.position, explosionRadius);
}

}

And this is my HP script:

public class EnemyStats: MonoBehaviour {

public static int Health = 100;
public int startHealth;
private int Reward = 50;

void Start ()
{
    Health = startHealth;
}



void Update ()
{
    if (Health <= 0)
    {
        PlayerStats.Money = PlayerStats.Money + Reward;
        Destroy(gameObject);
    }
}

}

Replace

 void Damage (Transform enemy)
 {
     EnemyStats.Health -= damage;
 }

With

void Damage (Transform enemy)
 {
    enemy.gameObject.GetComponent<EnemyStats>().Health -= damage;
 }

Currently, you were treating all enemy health as the exact same healthpool. All enemies share one pool, and when one got hit, they all lost health. This lowers the health of only a single enemy. However, you still have a global health pool, to fix that, Replace:

public static int Health = 100;

With:

public int Health = 100;

This will fix your problem.



Your base issue is that you don’t really understand how static and classes work, which is a very common mistake. A class is either static, as you did, or not static and requires instances. Basically, a static class is global and exists only once, where as a non static class requires an instance to be set up, and references to those instances. You don’t want a static class in this case. If you apply the changes I gave you, it’ll be fine, however I’d also recommend you take it a step further, and put the damage function on the enemy itself. For example in the bullet script, instead of the enemy variable being a transform, make it a GameObject. Access the transform by enemy.transform, and damage the enemy with

enemy.GetComponent<EnemyStats>().Damage(damage);

Then, have your enemy have a Damage function, like so:

Damage (int damage)
{
    Health -= damage;
}