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 :將場景添加到當前加載的場景中