繁体   English   中英

如何在 Unity 5 中使用场景管理器移动到下一个场景?

[英]How to move to next scene using scene manager in Unity 5?

我正在做一个使用 unity 4 的教程,他们正在使用这个:

Applicaiton.LoadLevel(Appliaction.loadedLevel +1);

以便进入下一个场景。 我使用的是 unity 5,它告诉我使用场景管理器,因为以前的方法现在已经过时了。

取代上述代码的新代码是什么?

Scene结构有一个buildIndex变量来存储索引。 因此,要加载下一个场景:

using UnityEngine.SceneManagement;

int currentSceneIndex = SceneManager.GetActiveScene().buildIndex; 
if(currentSceneIndex<SceneManager.sceneCount-1)
{
    SceneManager.LoadScene(currentSceneIndex + 1);
}
using UnityEngine; using UnityEngine.SceneManagement ; public class next_level : MonoBehaviour { public void next_levl(){ SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex +1 ) ; } }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM