Basic scoring not working

hi everyone, im trying to do a wave system with a score value, enemy dies increment 1 to the wavecounter and when the wave counter is equal to the wavelimit start next wave(which i havent created but thats another topic). Basically saying when the wave limit is reached start next wave.

Here´s the enemy code(the place where im trying to implement) :

public class Enemy : MonoBehaviour
{

public float EnemySpeed;

public float EnemyStoppingDistance;

public float EnemyReatreatDistance;

private float TimeBetweenShots;

public float StartTimeBetweenShots;

public int Health;

public GameObject Projectile;

private Transform Target;

public GameObject DeathEffect;

private GameObject objSpawn;

public int WaveLimit;

public int WaveCounter;


void Start()
{
    Target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
    TimeBetweenShots = StartTimeBetweenShots;
    objSpawn = (GameObject)GameObject.FindWithTag("Spawner");
}

void Update()
{
    if (Vector2.Distance(transform.position, Target.position) > EnemyStoppingDistance)
    {
        transform.position = Vector2.MoveTowards(transform.position, Target.position, EnemySpeed * Time.deltaTime);
    }
    else if (Vector2.Distance(transform.position, Target.position) < EnemyStoppingDistance && Vector2.Distance(transform.position, Target.position) > EnemyReatreatDistance)
    {
        transform.position = this.transform.position;
    }
    else if(Vector2.Distance(transform.position, Target.position) < EnemyReatreatDistance)
    {
        transform.position=Vector2.MoveTowards(transform.position, Target.position, -EnemySpeed * Time.deltaTime);
    }

    if (TimeBetweenShots <= 0)
    {
        Instantiate(Projectile, transform.position, Quaternion.identity);
        TimeBetweenShots = StartTimeBetweenShots;
    }
    else 
    {
        TimeBetweenShots -= Time.deltaTime;
    }

    if(Health<= 0)
    {
        
        Instantiate(DeathEffect, transform.position, Quaternion.identity);
        Destroy(gameObject);
        
       
    }

}
  public void OnDestroy()
  {
    
    WaveCounter++;
    if (WaveCounter == WaveLimit)
    {
        Debug.Log("WaveLimit reached");
    }
  }

public void TakeDamage(int Damage)
{
    Health -= Damage;
}

}

the exact place where the score system is is:

public void OnDestroy()

{

 WaveCounter++;
 if (WaveCounter == WaveLimit)
 {
     Debug.Log("WaveLimit reached");
 }

}
This log i put isnt appearing thats why i detected a problem.

I don’t see where you are calling OnDestroy, Destroy(gameObject) is a Unity function and will not call OnDestroy for you.

Try this:

if(Health<= 0)
     {
         OnDestroy();
         Instantiate(DeathEffect, transform.position, Quaternion.identity);
         Destroy(gameObject);          
     }

I don’t know if how the waves progress this is where you would want to call OnDestroy, but you need to call that function yourself.

Let me know if that is the problem.

the message is showing but only thing is that the counter number doesnt go up and if i try to set the limit to 2 or 3 it shows even if i didnt reach the limit,
thanks for responding im very new at unity and programming so im very apreciative of that.