【问题标题】:Application.LoadLevel("string") is obsolete [duplicate]Application.LoadLevel("string") 已过时 [重复]
【发布时间】:2016-06-28 17:47:25
【问题描述】:

我从一个拥有大量Application.LoadLevel("whatever"); 的人那里得到了一个代码。 Monodevelop 说这已经过时了,我应该改用SceneManager.LoadScene。我该怎么做?

实际上Application.LoadLevel("whatever"); 行不起作用,除非我将相应的场景添加到“构建设置”中

【问题讨论】:

  • 我刚刚读过它。怎么样? ..我尝试使用SceneManager.LoadScene("whatever"); 行,但找不到该类并且它给出了错误。我需要导入一些东西吗?
  • "whatever" 应该是现有场景的名称或您可以在构建设置中找到的场景索引(即,如果场景被添加到构建中,它是列表中的第 n 个,该索引)。提供有关您的“随便”的更多详细信息,以便我们提供帮助
  • 在您编辑后:然后您将其整理出来。考虑删除问题以保持清洁或添加您的解决方案作为答案并接受它
  • 编辑如何显示我整理出来了?我在澄清。 "whatever" 当然是现有场景的名称。他在不同场景的代码中使用了这行代码。我需要提及它有那么难吗? ...无论如何,没有你的帮助,我确实弄明白了

标签: unity3d scripting unity5


【解决方案1】:

只需像这样导入UnityEngine.SceneManagement

 using UnityEngine.SceneManagement;

然后将每个Application.LoadLevel("whatever"); 替换为:

SceneManager.LoadScene("whatever");

...也可以一行完成:

UnityEngine.SceneManagement.SceneManager.LoadScene("whatever");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 2015-07-17
    • 2020-04-29
    • 2016-12-02
    • 1970-01-01
    相关资源
    最近更新 更多