Spawner not working...?

On lesson 138. I’ve created a Spawner prefab and the code. I’m not sure why, but it’s not spawning any enemies. I’m sure it’s a simple mistake that I’m overlooking, so maybe a second set of eyes will help me. No errors are being thrown in the console

My EnemySpawner.cs file

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

public class EnemySpawner : MonoBehaviour
{
    bool spawn = true;
    [SerializeField] float minSpawnDelay = 1f;
    [SerializeField] float maxSpawnDelay = 5f;
    [SerializeField] Enemy enemyPrefab;

    // Start is called before the first frame update
    IEnumerable Start()
    {
        while (spawn) {
            yield return new WaitForSeconds(Random.Range(minSpawnDelay, maxSpawnDelay));
            SpawnEnemy();
        }
    }

    private void SpawnEnemy() {
        Instantiate(enemyPrefab, transform.position, transform.rotation);
    }

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

Hi,

Did you press the Play button in Unity? If so, did you get any error messages in your Console?

Yes and no.

I ended up figuring out the answer. The return should be IEnumerator not IEnumerable.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms