Infinite Runner Respawning Live Tutorial Question

I put the three objects onto the code as was instructed by the video and coded it correctly to my knowledge. It produces three randomly generated ground but only three. It stops at three without continuing to respawn. Look at my code to tell me if I did it incorrectly or if there is an updated version.

using UnityEngine;
using System.Collections;

public class Spawnscript : MonoBehaviour {
public GameObject[ ] obj;
public float spawnMin = 1f;
public float spawnMax = 2f;

// Use this for initialization
void Start () {
Spawn ();
}

void Spawn ()
{Instantiate (obj [Random.Range (0, obj.GetLength(0))], transform.position,Quaternion.identity);
Invoke (“Spawn”, Random.Range (spawnMin, spawnMax));
}
}

You want it to keep spawning forever?

Personally I don’t like using Invoke for anything.

Here’s a pretty straightforward implementation using a coroutine:

using UnityEngine;
using System.Collections;

public class Spawnscript : MonoBehaviour {
    public GameObject[] obj;
    public float spawnMin = 1f;
    public float spawnMax = 2f;

    // Use this for initialization
    void Start() {
        StartCoroutine(Spawn());
    }

    IEnumerator Spawn() {
        while(isActiveAndEnabled) {
            Instantiate(obj[Random.Range(0, obj.Length)], transform.position, Quaternion.identity);
            yield return new WaitForSeconds(Random.Range(spawnMin, spawnMax));
        }
    }
}

“Start” itself can actually be a coroutine if you give it an IEnumerator return type, which Unity will automatically start, but if you’re not familiar with these concepts I didn’t want to make it a confusing example.