问题
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