Version: 2021.1
Method group is Obsolete

SceneManager.UnloadScene

切换到手册
Obsolete public static bool UnloadScene (int sceneBuildIndex);
Obsolete public static bool UnloadScene (string sceneName);
Obsolete public static bool UnloadScene (SceneManagement.Scene scene);

参数

sceneBuildIndex Build Settings 中要卸载场景的索引。
sceneName 要卸载的场景的名称或路径。
scene 要卸载的场景。

返回

bool 如果场景已卸载,则返回 true。

描述

销毁所有与给定场景关联的游戏对象,并将场景从 SceneManager 中移除。

注意:不建议使用此函数,可以改用 UnloadSceneAsync

警告:无法在不同的物理和可见性回调(如 OnTriggerEnter 或 OnBecameVisible)过程中调用此函数,因此不建议使用。

提供的场景名称可以是完整场景路径(Build Settings 窗口中显示的路径),也可以只是场景名称。如果仅提供场景名称,此方法将加载场景列表中匹配的第一个场景。如果您有多个名称相同但路径不同的场景,应该使用完整的场景路径。 支持的格式示例:\ "Scene1"\ "Scene2"\ "Scenes/Scene3"\ "Scenes/Others/Scene3"\ "Assets/scenes/others/scene3.unity"\ \ 注意:sceneName 不区分大小写。 \ 注意:目前不会卸载资源,要释放资源内存,请调用 Resources.UnloadAllUnusedAssets。