Unity3d 重启当前场景 [英] Unity3d restart current scene
问题描述
好的,所以我正在尝试在按下 R 时重新启动场景,由于某种原因,我在统一控制台中收到了诸如意外符号 '}'"和解析错误"之类的错误.但是后来在 Microsoft Visual Studio 中,我得到了;预期".对以下代码有什么问题有任何想法吗?
Ok so I am trying to restart the scene on R being pressed and for some reason, I am getting errors like, well in the unity console: "unexpected symbol '}' " and "parsing error". But then in Microsoft visual studio I'm getting "; expected". Any ideas of what's wrong with the following code?
void Update() {
if (Input.GetKeyDown(KeyCode.R))
SceneManager.GetActiveScene().buildIndex
}
推荐答案
您必须要求场景管理器使用 LoadScene
You must ask the scene manager to load the scene using LoadScene
if (Input.GetKeyDown(KeyCode.R))
SceneManager.LoadScene( SceneManager.GetActiveScene().buildIndex ) ;
您只是在检索当前场景的构建索引.
You were just retrieving the build index of the current scene.
另外,关于你的编译错误,你忘记了行尾的分号;)
Also, about yourcompilling error, you have forgotten the semi-colon at the end of the line ;)
这篇关于Unity3d 重启当前场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!