I’m making a script to generate levels in an endless Runner, but I came across an issue any ideas on how to fix it?
public class GenerateLvl : MonoBehaviour
{
[FormerlySerializedAs("section")] public GameObject[] Section;
public int zPos = 50;
public bool creatingSection = false;
public int secNum;
void Update()
{
if (creatingSection == false)
{
creatingSection = true;
StartCoroutine(GenerateSection());
}
}
IEnumerator GenerateSection()
{
secNum = Random.Range(0, 3);
Instantiate(Section[secNum], new Vector3(0, 0, zPos), Quaternion.identity);
zPos += 50;
yield return new WaitForSeconds(2);
creatingSection = false;
}
}