Repository navigation
The GetAllLoadedScenes() Method
Narek Torosyan edited this page Nov 25, 2018
·
1 revision
This method extends SceneManager.
This method returns all current loaded scenes as a Scene array.
This method can be used for replacing the obsolete SceneManager.GetAllScenes() method.
// This script unloads all loaded scenes except a scene with a specified name.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using NUDev.PlusSharp;
public class UnloadAllScenesExcept : MonoBehaviour {
public string scene;
private SceneManager scm;
void Start () {
scm = new SceneManager();
StartCoroutine(Unload());
}
IEnumerator Unload () {
Scene[] scs = scm.GetAllLoadedScenes();
for (int i = 0; i < scs.Length; i++)
{
if (scs[i].name != scene)
{
yield return SceneManager.UnloadSceneAsync(scs[i].name);
}
}
}
}Excited? Download PlusSharp!
Have issues? Post them here!