Страница 1 из 1

Сцены по IEnumerator

СообщениеДобавлено: 15 янв 2017, 01:04
Shpak
Всем привет. Стала такая задача - загружать новую сцену каждые 30 секунд, бесконечно.
Т.е. есть массив, который хранит в себе названия сцен ( StartEff.massEff [StartEff.controlEff-- ] [ 0 ] ).
и есть IEnumerator, который выполняет через 30 сек тот бред, что я написала (((

Синтаксис:
Используется csharp
class StartEff // формируем список воспроизведения
    {
        public static List<List<string>> massEff = new List<List<string>>();
        public static int controlEfft = 0;
 }


////////////////////


Навесила просто на канву в каждой сцене.

Синтаксис:
Используется csharp
public class ControlEff : MonoBehaviour {

void Start () {
        PLAY();
    }
    public void PLAY()
    {
        try
        {
          if ( StartEfft.massEff [ StartEfft.controlEff ] [ 0 ] != null )
          {
                    StartCoroutine( Play_effect(  ) );
                    if ( StartEff.controlEff == 0 ) {
                       StartEff.controlEff++;
                       SceneManager.LoadScene( StartEff.massEff [ StartEff.controlEff-- ] [ 0 ] );  
                    }
            }
        }
        catch
        {
        }
    }

    IEnumerator Play_effect (  )
    {
        yield return new WaitForSeconds( 30f );
        try
        {  
                if ( StartEff.controlEff < StartEff.massEff.Count && StartEffect.controlEffectPlay != 0 )
                {
                    StartEff.controlEff++;
                    SceneManager.LoadScene( StartEff.massEff [ StartEff.controlEff-- ] [ 0 ] );
                }
                else {
                    StartEff.controlEff = 0;
                }
        }
        catch
        {
        }
    }
 

////////////////////

В итоге, все работает не так, как я ожидала, я так поняла, что IEnumerator зацикливается и все виснет.... [curved_hands]
Прошу помощи!!!! :(( :(( :(( ^:)^ ^:)^ ^:)^

Re: Сцены по IEnumerator

СообщениеДобавлено: 15 янв 2017, 02:08
samana
У нас сейчас ночь, но увидев ваш код я проснулся.
Попробуйте немного проще, без корутины. Например поместив этот скрипт в каждую сцену.

Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.SceneManagement;

public class ScenesChanger : MonoBehaviour
{
    private static int currentSceneIndex = 0;
    private static List<string> scenes = new List<string> { "scene_1", "scene_2", "scene_3" };

    void Start()
    {
        Invoke("loadNexScene", 30f); // 30 секунд
    }

    private void loadNexScene()
    {
        currentSceneIndex++;
        if (currentSceneIndex == scenes.Count) currentSceneIndex = 0;
        SceneManager.LoadScene(scenes[currentSceneIndex]);
    }
}

Re: Сцены по IEnumerator

СообщениеДобавлено: 15 янв 2017, 02:39
Shpak
:-o Invoke? Спасибо тебе, добрый человек, за прозрение)))