英文:
Argument 1: cannot convert from 'UnityEngine.SceneManagement.Scene' to 'string' [Assembly-CSharp] Error
问题
In Unity 2D,我试图编写一个脚本来加载下一个场景,但它不起作用并且报错,我漏掉了什么?
英文:
int Scenenumber=SceneManager.GetActiveScene().buildIndex;
public void NextLevel(){
SceneManager.LoadScene(SceneManager.GetSceneByBuildIndex(Scenenumber+1));
}
In unity 2d, I am trying to make a script to load next scene but it doesnt work and gives me and error what am I missing?
答案1
得分: 0
以下是翻译好的部分:
"你不需要在LoadScene内再次调用SceneManager。
只需像这样调用:
int Scenenumber = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(Scenenumber + 1);
如果仍然失败,请双重检查您的场景是否在Build Settings中可用,并且左侧的检查已启用。"
英文:
You don't need to call SceneManager again inside of LoadScene.
Just call like this:
int Scenenumber = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(Scenenumber + 1);
If it still failing, double check if your scene is available at Build Settings and the check on the left is enabled.
答案2
得分: 0
你必须使用 name
来加载:
int Scenenumber = SceneManager.GetActiveScene().buildIndex;
public void NextLevel(){
SceneManager.LoadScene(SceneManager.GetSceneByBuildIndex(Scenenumber+1).name);
}
或者
string SceneName = SceneManager.GetActiveScene().name;
public void NextLevel(){
SceneManager.LoadScene(SceneName);
}
英文:
You must use the name
to load:
int Scenenumber=SceneManager.GetActiveScene().buildIndex;
public void NextLevel(){
SceneManager.LoadScene(SceneManager.GetSceneByBuildIndex(Scenenumber+1).name);
}
or
string SceneName=SceneManager.GetActiveScene().name;;
public void NextLevel(){
SceneManager.LoadScene(SceneName);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论