Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

c# - 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". 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
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...