簡體   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