Problem with Coroutine - Wave message / objects spawning

Hello,

I want to have a code that shows information such as: “Wave 1”, then there is a 3-second break and then waves with objects appear, I tried various things and the word “Wave” appears at the same time objects are created, someone knows how should the code look like to achieve this?
Thank you in advance for your help.

The code responsible for displaying wave information:

WaveCounter.gameObject.SetActive(true);

        WaveCounter.text = "Wave " + CurrentWaveNumber;
      
        yield return new WaitForSeconds(3f);

        WaveCounter.gameObject.SetActive(false);

rest of code:

public IEnumerator WaveControllerCoroutine()
    {
 

        while (true)
        {

            if (OnWaveStarted != null)
            OnWaveStarted.Invoke(CurrentWaveNumber);


            itemSpawner.Spawning = true;
            otherspawner.Spawning = true;

            yield return new WaitForSeconds(WaveDuration);

            itemSpawner.Spawning = false;
            otherspawner.Spawning = false;

            yield return new WaitForSeconds(CooldownDuration);

            if (OnWaveEnded != null)
                OnWaveEnded.Invoke(CurrentWaveNumber);


            yield return new WaitForSeconds(BreakDuration);
           
                CurrentWaveNumber += 1;


          

        }
    }

Post the code of how you’re calling these

OnWaveStarted.Invoke(CurrentWaveNumber);

If you want one coroutine to yield until another coroutine has finished running, you have to chain them

It would look more like this

yield return StartCoroutine(DisplayWaveInfoCoroutine(CurrentWaveNumber));

Currently you are using events.

Perhaps you can use an IEnumerator Func delegate and Yield StartCoroutine that, I dunno.

Edit:

Yeah, you can yield a IEnumerator Func. That’s awesome

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DelegateCoroutineTest : MonoBehaviour
{
    private Func<int, IEnumerator> FuncCoroutine;
    // Start is called before the first frame update
    void Start()
    {
        FuncCoroutine = WaitCounterCoroutine;

        StartCoroutine(MainCoroutine());
    }

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

    private IEnumerator WaitCounterCoroutine(int seconds)
    {
        Debug.Log("Started WaitCounterCoroutine");

        for (int i = 0; i < seconds; i++)
        {
            yield return new WaitForSeconds(1f);
            Debug.Log(i);
        }

        Debug.Log("Finished WaitCounterCoroutine");
    }

    private IEnumerator MainCoroutine()
    {
        Debug.Log("Started MainCoroutine");

        yield return StartCoroutine(FuncCoroutine(5));

        Debug.Log("Finished MainCoroutine");
    }
}