Skip to Main Content






Unity tutorial

Add scenes into Build

Click on File > Build Settings

  • From the Scenes folder in Assets, drag in the Main Menu scene, then the Game scene, and then the End Screen scene.
  • Click on Build, create a new folder called "Builds", and save it in the folder (Creating a build creates a working build of the game)

Close the tab

Script for scene change

We will now add a code to change the scenes when: clicking on the Play button in the Main Menu scene and when clicking the Menu button in the End Screen scene.

 

Navigate to the Scripts folder

Right-click in the folder > Create > C# Script

Name the script "SceneChange", click on the script to open it in Visual Studio

Copy the following code into the script and save the file:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;//SceneManagement Library is require to load new scene in the game

public class SceneChange : MonoBehaviour
{
    public void PlayGame()
    {
        SceneManager.LoadScene(1);
    }
    public void MainMenu_button()
    {
        SceneManager.LoadScene(0);
    }

    public void QuitGame()
    {
        Application.Quit();
    }
}

 

Navigate to the Scenes folder

Click on the Main Menu scene

Click on the dropdown of Canvas > PlayButton, in the Inspector window:

  • From the Scripts folder, drag the SceneChange script
  • Click on the Plus sign of the On Click ()
  • Drag the SceneChange script into the placeholder
  • In the dropdown for function > SceneChange > PlayGame

Click on the dropdown of Canvas > QuitButton, in the Inspector window:

  • From the Scripts folder, drag the SceneChange script
  • Click on the Plus sign of the On Click ()
  • Drag the SceneChange script into the placeholder
  • In the dropdown for function > SceneChange > QuitGame

 

Navigate to the Scenes folder

Click on the End Screen scene

Click on the dropdown of Canvas > MenuButton, in the Inspector window:

  • From the Scripts folder, drag the SceneChange script to the inspector window of the MenuButton
  • Click on the Plus sign of the On Click ()
  • Drag the SceneChange script into the placeholder
  • In the dropdown for function > SceneChange > MainMenu_button


Navigate to the Scenes folder

Click on the Game scene

Click on Window tab > Rendering > Lighting settings

Check the Auto Generate box