Argument 1: cannot convert from 'UnityEngine.SceneManagement.Scene' to 'string' [Assembly-CSharp] Error

huangapple go评论62阅读模式
英文:

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);
    }

huangapple
  • 本文由 发表于 2023年4月17日 20:49:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035336.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定