using System.Collections;
1using System.Collections.Generic; 2using UnityEngine; 3using UnityEngine.UI; 4using UnityEngine.SceneManagement; 5 6public class TEST : MonoBehaviour { 7 8 public Button btn; 9 10 public void Start() 11 { 12 btn.onClick.AddListener(() => Load()); 13 } 14 15 public void Load() 16 { 17 AsyncOperation ass=SceneManager.LoadSceneAsync("02",LoadSceneMode.Additive); 18 } 19 20 21}
代码比较简单 主要是了解
1SceneManager.LoadSceneAsync(异步加载)的参数含义:《1》public static AsyncOperation LoadSceneAsync(int sceneBuildIndex, LoadSceneMode mode); int sceneBuildIndex:是在scenes in build中场景的下标(一般不建议使用该方法) LoadSceneMode mode:LoadScenesMode 是个枚举 有两种 2 3// 摘要: 4 // Used when loading a scene in a player. 5 public enum LoadSceneMode 6 { 7 // 摘要: 8 // Closes all current loaded scenes and loads a scene. 9 Single = 0, 10 // 11 // 摘要: 12 // Adds the scene to the current loaded scenes. 13 Additive = 1, 14 }
single:关闭所有当前加载的场景并加载场景。
Additive :将场景添加到当前加载的场景中