我正在制作一款坦克战游戏,每轮后都会随机生成新的关卡。在我的游戏管理器中,我试图让回合从随机范围索引中的附加加载场景开始,然后以卸载场景结束,然后加载到新的随机场景中。然而,我所做的每一次尝试都会导致某种形式的错误。
我一直被引导到 LoadLevelAsync,但它似乎只是给了我更多似乎没有人回答的问题。
目前的布局如下:
//Load random level scene
int index = Random.Range(2, 4);
SceneManager.LoadSceneAsync(index, LoadSceneMode.Additive);
Debug.Log("SceneLoaded");
//Unload current scene and load new random level scene
int index = Random.Range(2, 4);
SceneManager.UnloadSceneAsync(index);
SceneManager.LoadSceneAsync(index, LoadSceneMode.Additive);
Debug.Log("SceneLoaded");
按照此代码的设置方式,如果新的随机级别是先前使用的级别的重复,那么它似乎工作正常,但如果调用的级别不同,那么它会给我一个错误并崩溃。
非常感谢任何关于从这里去哪里的建议。我无论如何都不是程序员,所以简单而详细的解释是必要的。谢谢。
我找到了工作解决方案。也许它仍然具有相关性。
// Get count of loaded Scenes and last index
var lastSceneIndex = SceneManager.sceneCount - 1
// Get last Scene by index in all loaded Scenes
var lastLoadedScene = SceneManager.GetSceneAt(lastSceneIndex)
// Unload Scene
SceneManager.UnloadSceneAsync(lastLoadedScene);
场景管理器.GetSceneAt() https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.GetSceneAt.html- 获取场景管理器加载场景列表中索引处的场景
场景管理器.sceneCount https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager-sceneCount.html- 当前加载的场景总数
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)