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);
}
}
}