Loading Scenes in Unity
So far the game has just had one scene, but now it’s time to add another scene and enable switching from the main menu to game scene. The first step is creating the main menu scene. Make new scene by selecting File->New Scene. The save the new scene as “Main_Menu”. Create the UI for the main menu. For examples of how you can do that look back at my UI tutorial. Make sure you add a button to the UI for the player to click to start the game.
Next, go to File->Build Settings and add both scenes to it. You want to have the main menu as the first scene so you may need to delete any scenes already there and then add all of the scenes starting with the main menu. You can do that by dragging and dropping them onto it.
Next, create a main menu script and attach it to the canvas. At the top of the script make sure you include using UnityEngine.SceneManagement;
so that you have access to SceneManager to load the scene. Create a function that will load the game scene.
public void LoadGame()
{
SceneManager.LoadScene(1); //Game Scene
}
Last, go to the button in the editor. You will connect the function you just created to the button. Add a new on click action to the button. Drag the Canvas onto the object slot. Then from the function drop down select your script then function.
Now when you start up the main menu scene you can click the “New Game” button and it will launch your game scene and start the game.
Good Luck Adventurer!
-Chris