Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Next Scene doesn't work all the time

Discussion in '2D' started by SuperCrow2, Mar 17, 2018.

  1. SuperCrow2

    SuperCrow2

    Joined:
    Mar 8, 2018
    Posts:
    584
    Can I not have more than one button on the same scene that once clicked goes to the next scene (the same one?). Clicking on either button is supposed to bring you to level 1. The problem is, the start game function only appears for one of the buttons, I can't find that function for the second one even though i did all the coding right.
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Sure you can have two buttons that call a method that load scene 1.

    When you say the function doesn't appear, do you mean it's not listed in the inspector? Did you make sure you dropped a game object into the slot and not the script itself, and then chose the method from the drop down menu?

    Please explain if I got that wrong. :)
     
  3. SuperCrow2

    SuperCrow2

    Joined:
    Mar 8, 2018
    Posts:
    584
    Coding in Unity is so weird. In order to make the buttons to go to the next scene you always need that start game function (after typing "start" in the new script search box) then that somehow magically makes it work. So like I am going to have several more "start (number) start1 start2 etc... functions I add the number at the end because you cant have the same function name more than once. Yet even with naming the function start1() that magically works it brings up "start" and then "StartGame"

    When it comes to choosing your function it's under "button" then a new list appears and then StartGame() is there.

    after going to add component and new script and put in "start2" "start" wouldn't appear.

    However, I just found out after typing all the above that all I need is to make the function one time then just simply add that to each scene that I need to switch to after clicking the button. For instance, once I make the function work for "Play game" then the next scene with all the game modes I can just simply use the "Play Game" icon (under runtime C# in the On Click box. for each game mode.

    But to answer your question, yes I did drag the game object to it.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I followed most of what you said. Just to be clear, though, in the end you did get it working, yes? :)
    I suppose it takes a bit of getting used to (and a bit of practice) to use Unity/script in Unity...

    You could have just 1 script that has a number or string variable, and add that script to any game object (even the button itself), and then connect up to said function. All you'd do differently per button/scene, is to supply the variable's name or number and all should be working. :)