Page 1 sur 1

Bug coroutines

Publié : 24 Sep 2020 17:44
par Valva
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);
            }
        }

Re: Bug coroutines

Publié : 24 Sep 2020 18:05
par Max
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())

Re: Bug coroutines

Publié : 24 Sep 2020 19:11
par jmhoubre
Bizarre que Visual Studio ne couine pas...