unity中加载下一个场景且不销毁当前场景的方法

1.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class TEST : MonoBehaviour {

    public Button btn;

    public void Start()
    {
        btn.onClick.AddListener(() => Load());
    }

    public void Load()
    {
        AsyncOperation  ass=SceneManager.LoadSceneAsync("02",LoadSceneMode.Additive);
    }


}

代码比较简单 主要是了解

SceneManager.LoadSceneAsync(异步加载)的参数含义:

《1》public static AsyncOperation LoadSceneAsync(int sceneBuildIndex, LoadSceneMode mode);
    int sceneBuildIndex:是在scenes in build中场景的下标(一般不建议使用该方法)
    LoadSceneMode mode:LoadScenesMode 是个枚举 有两种
    
    // 摘要: 
    //     Used when loading a scene in a player.
    public enum LoadSceneMode
    {
        // 摘要: 
        //     Closes all current loaded scenes and loads a scene.
        Single = 0,
        //
        // 摘要: 
        //     Adds the scene to the current loaded scenes.
        Additive = 1,
    }

     single:关闭所有当前加载的场景并加载场景。
   Additive :将场景添加到当前加载的场景中

      

 


原文地址:https://www.cnblogs.com/nanyang0310/p/9117217.html