How can i stop this generation, add a totally different floor to it, and then restart the generation? <3,

public GameObject section;
public int zPos = 10;
public bool creatingSection = false;
public int secNum;

void Update()
    if (creatingSection == false)
        creatingSection = true;

IEnumerator GenerateFloor()
    secNum = Random.Range(0, 36);
    Instantiate(section[secNum], new Vector3(0, 0, zPos), Quaternion.identity);
    zPos += 10;
    yield return new WaitForSeconds(1);
    creatingSection = false;


I dont understand what you mean with “add a totally different floor”. This function generates a floor by instantiating it from a list… What do you mean with adda a totally different floor?

I want to stop, then use some conditions before StartCoroutine() to control when is executed…


I think my question was misleading. So i just want to stop this generate at a certain point. Like after 50 “floor” it should stop generate. And i want to restart it, whenever i want. I just started 1 month ago from 0, and i just copied this script. I think thats why my question is dumb.