[Solved]Spawner: no idea why this is not working.

Hello everyone, i created this script for spawning prefabs but i don’t know why it’s not working, the console doesn’t show me any errors or warnings. I’ll be glad if you could explain to me what i’ve done wrong.

using UnityEngine;
using System.Collections;

public class Spawner : MonoBehaviour {

    public GameObject prefabToSpawn;

    public float spawnInterval;
    public float waveCooldown;

    public int numberOfPrefabs;
    public int numberOfWaves;

    void Start () {
        spawnWaves (numberOfWaves, waveCooldown, numberOfPrefabs, spawnInterval);
    }

    IEnumerator spawnWaves(int noWaves, float cooldown, int noPrefabs, float interval)
    {   
        // Start counting waves
        for(int i = 1; i <= noWaves; i++)
        {
            Debug.Log("wave " + i);
            // Start counting prefabs
            for(int j = 1; j <= noPrefabs; j++)
            {
                    Debug.Log("prefab " + j);
                    Instantiate(prefabToSpawn, transform.position, Quaternion.identity);
                    yield return new WaitForSeconds(interval);
            }
            yield return new WaitForSeconds(cooldown);
        }
    }
}

You need to use StartCoroutine on spawnWaves :

StartCoroutine(spawnWaves (numberOfWaves, waveCooldown, numberOfPrefabs, spawnInterval));

Also instead of returning a new WaitForSeconds each iteration and wave, couldn`t you just create it one and reuse it?

IEnumerator spawnWaves(int noWaves, float cooldown, int noPrefabs, float interval)
    { 
WaitForSeconds wInterval= new WaitForSeconds(interval);
WaitForSeconds wWaves = new WaitForSeconds(cooldown);
        // Start counting waves
        for(int i = 1; i <= noWaves; i++)
        {
            Debug.Log("wave " + i);
            // Start counting prefabs
            for(int j = 1; j <= noPrefabs; j++)
            {
                    Debug.Log("prefab " + j);
                    Instantiate(prefabToSpawn, transform.position, Quaternion.identity);
                    yield return wInterval;
            }
            yield return wWaves;
        }
    }

Just to save on some redundant object creation.

Thank you for your fast answer, it works perfectly.