Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question Load scene on key press.

Discussion in 'Scripting' started by BigEd22, Jan 16, 2021.

  1. BigEd22

    BigEd22

    Joined:
    Nov 5, 2020
    Posts:
    2
    I am trying to make the game wait for the user to press a certain key to restart, am I dumb?



    Code (CSharp):
    1.  if (Input.GetKey("r"))
    2. {
    3. SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    4. }
     
  2. BigEd22

    BigEd22

    Joined:
    Nov 5, 2020
    Posts:
    2
    Nevermind, figured it out.
     
  3. MisterWaller

    MisterWaller

    Joined:
    Apr 23, 2021
    Posts:
    3
    Well, what was the solution?
     
  4. MartinMa_

    MartinMa_

    Joined:
    Jan 3, 2021
    Posts:
    455
    Code (CSharp):
    1.     if (Input.GetKey(KeyCode.R))
    2.     {
    3.     SceneManager.LoadScene("SceneName");
    4.     }
    5.  
    This should be solution.

    Code what he used above is if you want get name of active scene.
     
  5. MisterWaller

    MisterWaller

    Joined:
    Apr 23, 2021
    Posts:
    3
    Funny enough, I figured it out shortly after posting it, except mine was tied to "return" or "enter". Thanks, though!