Unity3d重启当前场景 [英] Unity3d restart current scene
本文介绍了Unity3d重启当前场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,所以我试图在按下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
}
推荐答案
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屋!
查看全文