How do I start a Coroutine / Fixing a compiler error

Here is my C# code:

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

public class GenerareLevel : MonoBehaviour
{
    public GameObject [ ];
    public int zPos = 69;
    public bool creatingSection = false;
    public int secNum;

    // Start is called before the first frame update
    void Start()
    {
        if (creatingSection == false); {
         
            creatingSection = true;
            StartCoroutine(GenerateSection())

        }

    }

    IEnumenator GenerareSection()

    // Update is called once per frame
    void Update()
    {
        secNum = Random.range(0, 3);
        Instantiate(section[secnum], new Vector3(0, 0, zPos), Quaternion.identity);
        zPos += 69;
        yield return new WaitForSeconds(2);
        creatingSection = false;
    }
}

You also haven’t actually defined the IEnumertor at all, this may also be causing a compile issue.

IEnumenator GenerareSection()

Right I stopped at the first issue I noticed but there is more there is a semi colon here

This is empty…?

Where is the name of the gameObject?

Yield in Update?

secnum should be secNum

You should really use an IDE like Visual studio to avoid small mistakes like that… here is a fix of your code:

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

public class GenerareLevel : MonoBehaviour {

    public GameObject[] sections;
    public int zPos = 69;
    public bool creatingSection = false;

    void Start()  {
        if (creatingSection == false) {
            creatingSection = true;
            StartCoroutine(GenerateSection());
        }
    }
    
    private void Update() {
        if (Input.GetKeyDown(KeyCode.Space)) {
            if (creatingSection == false) {
                creatingSection = true;
                StartCoroutine(GenerateSection());
            }
        }
    }

    IEnumenator GenerareSection() {
        int secNum = Random.range(0, sections.Length);
        Instantiate(sections[secNum], new Vector3(0, 0, zPos), Quaternion.identity);
        zPos += 69;
        yield return new WaitForSeconds(2);
        creatingSection = false;
    }

}

Hello @Liamantor,

You forgot a semi-colon ; here
You can try using an IDE like Visual studio, it will tell you whenever you forget something like this, also next time try to share the compile error so we can help you easily :+1: