UnityスイッチのロードシーンSceneManager.LoadScene
Unity Switch Loading Scene Scenemanager
SceneManager.LoadScene
public static void LoadScene(int sceneBuildIndex、SceneManagement.LoadSceneMode mode = LoadSceneMode.Single)
public static void LoadScene(string sceneName、SceneManagement.LoadSceneMode mode = LoadSceneMode.Single)
ビルド設定で、名前またはインデックスでシーンをロードします。
例1:シーン名でロードし、前のシーンを破棄しない
using UnityEngine using UnityEngine.SceneManagement//Use scene manager public class ExampleClass : MonoBehaviour{ void Start() { //Use LoadScene to load the scene //The second parameter AddSceneMode.Additive means that the current scene is not destroyed and the required scene is loaded SceneManager.LoadScene('OtherSceneName', LoadSceneMode.Additive) } }
例2:インデックスでロードし、現在のシーンを破棄します
using UnityEngine using UnityEngine.SceneManagement//Use scene manager public class ExampleClass : MonoBehaviour{ //Jump scene void LoadLevel(int level) { ScenesArgs e = new ScenesArgs() //Get the current scene index e.scnesIndex = SceneManager.GetActiveScene().buildIndex //Send exit scene event SendEvent(Consts.E_ExitScenes, e) //Send loading new scene event //LoadSceneMode.Single: destroy the current scene, load the scene to be loaded SceneManager.LoadScene(level,LoadSceneMode.Single) } }