1
\$\begingroup\$

I'm in the start screen scene of my game and I'm trying to load the actual game. I use the following code:

public void LoadGame(){
        SceneManager.LoadScene ("Main", LoadSceneMode.Single);
    }

I set this method to be called when a button in the UI is clicked. When testing in the game in the unity IDE, clicking the button doesn't do anything. Is my code wrong, is the IDE screwing up, or will clicking the button never do anything in the ide?

\$\endgroup\$
6
  • \$\begingroup\$ Add Debug.Log("Clicked!"); before SceneManager.LoadScene and check in the console if it gets fired. \$\endgroup\$
    – Jacob
    Commented Jun 18, 2017 at 21:10
  • \$\begingroup\$ @Spectre I forgot to add the scene to the build settings....#theTroublesOfANewbie \$\endgroup\$
    – Joel J.
    Commented Jun 18, 2017 at 21:15
  • \$\begingroup\$ Yep. And you should get an error in the console saying "Trying to load a scene which is not added to the build" blah blah. Look at the console, always. And debug things with Log()'s \$\endgroup\$
    – Jacob
    Commented Jun 18, 2017 at 21:18
  • \$\begingroup\$ If you solved your problem by yourself, post an answer with the solution and accept it :) \$\endgroup\$
    – Jacob
    Commented Jun 18, 2017 at 21:18
  • \$\begingroup\$ @Spectre done and thx for the adivce \$\endgroup\$
    – Joel J.
    Commented Jun 18, 2017 at 21:19

1 Answer 1

1
\$\begingroup\$

Turns out the code works. Here "Main" is the name of the scene and LoadSceneMode.Single is one element of an enumeration. Remember to add all scenes to the build settings.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .