Bug coroutines

Questions à propos du scripting. Hors Shader, GUI, Audio et Mobile.
Valva
Messages : 23
Inscription : 30 Mai 2020 17:10

Bug coroutines

Message par Valva » 24 Sep 2020 17:44

Bonjour je ne comprends pas il me dit le nom "part 2 n'existe pas dans le contexte actuel", pourtant ma coroutine est déclaré.

Code : Tout sélectionner

private void Start()
    {
        spawnWait = 1.5f;
        StartCoroutine(waitSpawner());
        StartCoroutine(part2());
        StartCoroutine(WaitDown2));
        prefabList.Add(Prefab1);
        prefabList.Add(Prefab2);
        prefabList.Add(Prefab3);
        prefabList.Add(Prefab4);
        prefabList.Add(Prefab5);
        prefabList.Add(Prefab6);
        prefabList.Add(Prefab7);
        prefabList.Add(Prefab8);

        prefabList2.Add(Prefab1);
        prefabList2.Add(Prefab2);
        prefabList2.Add(Prefab3);
        prefabList2.Add(Prefab4);
        prefabList2.Add(Prefab5);
        prefabList2.Add(Prefab6);
        prefabList2.Add(Prefab7);
        prefabList2.Add(Prefab8);
    }



    IEnumerator waitSpawner()
    {
        yield return new WaitForSeconds(startWait);

        while (!stop)
        {
            Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), Random.Range(-spawnValues.y, spawnValues.y), 0);

            int prefabIndex = UnityEngine.Random.Range(0, 2);
            int prefabIndex2 = UnityEngine.Random.Range(0, 2);

            Instantiate(prefabList[prefabIndex], spawnPosition + transform.TransformPoint(0, 0, 0), gameObject.transform.rotation);
            Instantiate(prefabList2[prefabIndex2], spawnPosition + transform.TransformPoint(0, -1, 0), gameObject.transform.rotation);

            yield return new WaitForSeconds(spawnWait);
        }

    IEnumerator part2()
        {
          yield return new WaitForSeconds(15f);

            stop = false;

            while (!stop1)
            {
                Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), Random.Range(-spawnValues.y, spawnValues.y), 0);

                int prefabIndex = UnityEngine.Random.Range(0, 4);
                int prefabIndex2 = UnityEngine.Random.Range(0, 4);

                Instantiate(prefabList[prefabIndex], spawnPosition + transform.TransformPoint(0, 0, 0), gameObject.transform.rotation);
                Instantiate(prefabList2[prefabIndex2], spawnPosition + transform.TransformPoint(0, -1, 0), gameObject.transform.rotation);

                yield return new WaitForSeconds(spawnWait);
            }
        }

Avatar de l’utilisateur
Max
Messages : 8765
Inscription : 30 Juil 2011 13:57
Contact :

Re: Bug coroutines

Message par Max » 24 Sep 2020 18:05

Bonsoir,

au niveau de ta coroutine waitSpawner(), il manque un } pour clôturer la définition de la fonction, ce qui encapsule la routine suivante ( part2())
Image
Pas d'aide par MP, le forum est là pour ça.
En cas de doute sur les bonnes pratiques à adopter sur le forum, consulter la Charte et sa FAQ

Avatar de l’utilisateur
jmhoubre
Messages : 851
Inscription : 05 Oct 2019 22:05

Re: Bug coroutines

Message par jmhoubre » 24 Sep 2020 19:11

Bizarre que Visual Studio ne couine pas...

Répondre

Revenir vers « Scripting »