Unity3d restart current scene

落爺英雄遲暮 提交于 2019-12-20 04:36:12

问题


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
}

回答1:


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 ;)




回答2:


just close the window and restart unity application, simple as that



来源:https://stackoverflow.com/questions/41644156/unity3d-restart-current-scene

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!