Загрузка / выгрузка уровней с использованием SceneManager.LoadScene (int, LoadSceneMode.Additive) / SceneManager.UnloadSceneAsync (int); Удаляет уровень по умолчанию - PullRequest
0 голосов
/ 22 апреля 2019

Используя аддитивную загрузку в проекте Unity, загрузите уровень по умолчанию (Game manager), затем запустите метод, чтобы выбрать и активировать аддитивные уровни (Lighting / Map).В игре есть раунды, и в конце каждого раунда я запускаю метод, предназначенный для выгрузки аддитивных уровней (Lighting / Map), однако он также удаляет уровень по умолчанию.

Ошибка при сбое: Дисплей 1 Нет рендеринга камер

Ссылка на страницы документации Unity;

https://docs.unity3d.com/ScriptReference/SceneManagement.UnloadSceneOptions.html

https://docs.unity3d.com/ScriptReference/SceneManagement.LoadSceneMode.html

Section for loading in level:

        private IEnumerator RoundStarting ()
        {
            //Calling method meant to load in additive levels. Seems to work...
            LoadMapForRound();
            // As soon as the round starts reset the tanks and make sure they can't move.
            ResetAllTanks ();
            DisableTankControl ();

            // Snap the camera's zoom and position to something appropriate for the reset tanks.
            m_CameraControl.SetStartPositionAndSize ();

            // Increment the round number and display text showing the players what round it is.
            m_RoundNumber++;
            m_MessageText.text = "ROUND " + m_RoundNumber;

            // Wait for the specified length of time until yielding control back to the game loop.
            yield return m_StartWait;
        }

        //Method meant to load in additive levels.
        private void LoadMapForRound()
        {
            int LevelIndex = Random.Range(2, 4);
            SceneManager.LoadScene(1, LoadSceneMode.Additive);
            SceneManager.LoadScene(LevelIndex, LoadSceneMode.Additive);
            //Debug.Log("SceneLoaded");
        }

Section for unloading level:

 private IEnumerator RoundEnding ()
        {
            // Stop tanks from moving.
            DisableTankControl();

            // Clear the winner from the previous round.
            m_RoundWinner = null;

            // See if there is a winner now the round is over.
            m_RoundWinner = GetRoundWinner();

            // If there is a winner, increment their score.
            if (m_RoundWinner != null)
                m_RoundWinner.m_Wins++;

            // Now the winner's score has been incremented, see if someone has one the game.
            m_GameWinner = GetGameWinner();

            // Get a message based on the scores and whether or not there is a game winner and display it.
            string message = EndMessage();
            m_MessageText.text = message;

            // Wait for the specified length of time until yielding control back to the game loop.
            yield return m_EndWait;

            //calling ethod meant to unload levels, but ends up unloading default level as well.
            DestroyRoundMap();
        }

        //Method meant to unload levels
        private  void DestroyRoundMap()
        {
            SceneManager.UnloadSceneAsync(LevelIndex);
            SceneManager.UnloadSceneAsync(1);
        }

Unload additive levels (Light/Map) at rounds end, keep default level (0), instead the default level gets unloaded 

и вылетает игра.

1 Ответ

0 голосов
/ 25 апреля 2019
Included local variable within the LoadMapForRound for the Global Variable to be equal to.

    private void LoadMapForRound()
    {
        int mapChosen = Random.Range(2, 4); Solution Line
        LevelLoaded = mapChosen;
        SceneManager.LoadScene(LevelLoaded, LoadSceneMode.Additive);
        SceneManager.LoadScene(1, LoadSceneMode.Additive);
        //Debug.Log("SceneLoaded");
    }

Получил идею для решения из отдельной ветки по тому же вопросу.Тема здесь: Как выгрузить аддитивные сцены?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...