Enemy wave spawner in unity

I’m trying to create a wave spawner for a top down game that I’m creating. I have created the wave spawner script but when I hit play, nothing happens. The countdown doesn’t begin. Ideally it should start from 2, once it reaches 0, the first wave should spawn with one enemy. Once that enemy is killed, the countdown should begin from 5 and once 0 is reached, the next wave with 2 enemies should begin and so on. The new wave should not begin until all the current enemies are destroyed.

public enum SpawnState { SPAWNING, WAITING, COUNTING };

public SpawnState state = SpawnState.COUNTING;

public Transform enemy;

public float timeBetweenWaves = 5f;
public float countDown = 2f;

private int waveIndex = 0;

public float searchCountdown = 1f;   

void Update()
{        
  if (state == SpawnState.WAITING)
  {           
    if (!EnemyisAlive())
       {
          WaveCompleted();
        }
        else
        {                
            return;
        }
    }

  if (countDown <= 0f)
  {          
      if (state != SpawnState.SPAWNING)
      {              
          StartCoroutine(SpawnWave());
          countDown = timeBetweenWaves;
      }
      else
      {              
          countDown -= Time.deltaTime;
      }

  }

}

void WaveCompleted()
{        
    state = SpawnState.COUNTING;
    countDown = timeBetweenWaves;
    SpawnWave();        
}

bool EnemyisAlive()
{        
    searchCountdown -= Time.deltaTime;
    if (searchCountdown <= 0)
    {
        searchCountdown = 1f;
        if (GameObject.FindGameObjectsWithTag("Enemy").Length == 0)
        {
            return false;
        }
    }
    return true;
 }

IEnumerator SpawnWave()
 {        
    state = SpawnState.SPAWNING;
    waveIndex++;
    for (int i = 0; i < waveIndex; i++)
    {
        SpawnEnemy();
        yield return new WaitForSeconds(0.5f);

    }
    state = SpawnState.WAITING;
    yield break;
 }

void SpawnEnemy()
 {
    Instantiate(enemy, transform.position, transform.rotation);
 }   `

looks like you dont decrement the countdown unless the countdown is below zero. which it wont ever be, since thats the only time you decrement it. I think you just need to move the “else decrement” outside of that “countdown checking if”:

   if (countDown <= 0f)
   {          
       if (state != SpawnState.SPAWNING)
       {              
           StartCoroutine(SpawnWave());
           countDown = timeBetweenWaves;
       }
   }
   else
   {              
        countDown -= Time.deltaTime;
   }