[英]Unity3d restart current scene
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".好的,所以我正在尝试在按下 R 时重新启动场景,并且出于某种原因,我在统一控制台中收到诸如“意外符号 '}'”和“解析错误”之类的错误。 But then in Microsoft visual studio I'm getting "; expected".
但是后来在 Microsoft Visual Studio 中,我得到了“;预期”。 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您必须要求场景管理器使用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 ;)另外,关于你的编译错误,你忘记了行尾的分号;)
我可以说下面的代码可能是最简单的方法;
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
只需关闭窗口并重新启动统一应用程序,就这么简单
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.