Unity3d重启当前场景

Unity3d restart current scene

好的,所以我试图在按下 R 时重新启动场景,出于某种原因,我在统一控制台中收到类似错误:"unexpected symbol '}' " 和 "parsing error"。但是后来在 Microsoft visual studio 中我得到了“;预期”。对以下代码有什么问题有什么想法吗?

void Update() {
    if (Input.GetKeyDown(KeyCode.R))  
        SceneManager.GetActiveScene().buildIndex
}

你必须要求场景管理器使用LoadScene

加载场景
if (Input.GetKeyDown(KeyCode.R))  
    SceneManager.LoadScene( SceneManager.GetActiveScene().buildIndex ) ;

您刚刚检索了当前场景的构建索引。

此外,关于您的编译错误,您忘记了行尾的 semi-colon ;)

只需关闭 window 并重新启动 unity 应用程序,就这么简单

我可以说下面的代码可能是最简单的方法;

SceneManager.LoadScene(SceneManager.GetActiveScene().name);