UnityEngine.SceneManagement.SceneManager.GetSceneByBuildIndex C# (CSharp) Method

GetSceneByBuildIndex() public static method

Get a scene struct from a build index.

public static GetSceneByBuildIndex ( int buildIndex ) : Scene
buildIndex int Build index as shown in the Build Settings window.
return Scene
        public static Scene GetSceneByBuildIndex(int buildIndex)
        {
            Scene scene;
            INTERNAL_CALL_GetSceneByBuildIndex(buildIndex, out scene);
            return scene;
        }

Usage Example

コード例 #1
0
        public static void LoadSceneById(int id, bool force = false)
        {
            if (id >= GetSceneCount())
            {
                throw new Exception("Scene Index outisde of Range");
            }

            int   index = 1 + id;
            Scene scene = SCM.GetSceneByBuildIndex(index);

            if (force)
            {
                if (!scene.isLoaded)
                {
                    SCM.LoadScene(index);
                }
                else
                {
                    SCM.LoadScene(scene.name);
                }
            }
            else
            if (!scene.isLoaded)
            {
                SCM.LoadSceneAsync(index);
            }
            else
            {
                SCM.LoadSceneAsync(scene.name);
            }
        }
All Usage Examples Of UnityEngine.SceneManagement.SceneManager::GetSceneByBuildIndex