Beginning Essentials

Creating a Menu

You don’t have access to this lesson
Please register or sign in to access the course content.

There is a tutorial on Unity covering this.

Create a new blank Scene

Save the Scene

Add a Game Object UI Button

A button will be added to the Scene

Move it around as you would any object.

Modify the button as you want

Changing the Text is hidden away

In the hierarchy panel open the Button object and edit the Text Object inside it.

Open the Button panel in the inspector

You can customise the button here further

Drag in the game object that you would like to have the button modify

You can select from all of the assets in the program. Or a Script that has a function[1] to run

We now need[2] to create a GameController, this will manage the game logic.

Create a new empty GameObject and rename it GameController

Drag the GameController object into the Project[3] panel

Create a new Script called ButtonManager.

Add the code below

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class ButtonManager : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    public void GotoSampleScene()
    {
        SceneManager.LoadScene("SampleScene");
    }

    public void GotoMenuScene()
    {
        SceneManager.LoadScene("Menu");
    }
}

We need to import the Unity SceneManager. This is done with the line using UnityEngine.SceneManager;

We create two functions to switch[4] between the scenes.

This code creates a function called GotoSampleScene. When it is called the SceneManager uses the LoadScene method and will load the scene named SampleScene

Note that the argument given to the LoadScene() method takes a string[5] argument.

This argument is the exact name of the scene.

Add the ButtonManager script to the GameController object.

Now we need to add the script code to the button

Using the OnClick property in the Inspector add the ButtonManager script

Change No Function[1] to the function / method you want to call.

You will see a list of the options.

Select ButtonManager and then the appropriate method.

In this case[6] GotoSampleScene()

Run the program.

We will see an error

This is because we haven’t added the Scene to the build settings for the project[3].

Open the Sample Scene.

Go to File and select Build Settings…

Click Add Open Scenes

Close the Build Settings

Repeat this for any other Scenes

You can now create a button and switch between different scenes.

Terms definitions
2. need. An identified requirement of a person, group, or environment[8]. A need is identified from an issue[11] and sits within a context[12]. Technological practice[7] can be undertaken in an attempt to meet an identified need.
3. Project. A series of tasks that need to be completed in order to reach a specific outcome[13]
4. switch. A control[14] mechanism in which the value of a variable[9] or expression changes the execution of a program and which usually involves multiple branches.
5. string. A data type[10] used to store text. Often enclosed in “” or ”
Terms definitions
1. function. There is a tutorial on Unity covering this. Create a new blank Scene Save the Scene Add a Game Object UI Button A button will be added to the Scene Move it around as you would any object. Modify the button as you want Changing the Text is hidden away In the hierarchy panel open […]
2. need. There is a tutorial on Unity covering this. Create a new blank Scene Save the Scene Add a Game Object UI Button A button will be added to the Scene Move it around as you would any object. Modify the button as you want Changing the Text is hidden away In the hierarchy panel open […]
3. Project. There is a tutorial on Unity covering this. Create a new blank Scene Save the Scene Add a Game Object UI Button A button will be added to the Scene Move it around as you would any object. Modify the button as you want Changing the Text is hidden away In the hierarchy panel open […]
4. switch. There is a tutorial on Unity covering this. Create a new blank Scene Save the Scene Add a Game Object UI Button A button will be added to the Scene Move it around as you would any object. Modify the button as you want Changing the Text is hidden away In the hierarchy panel open […]
5. string. There is a tutorial on Unity covering this. Create a new blank Scene Save the Scene Add a Game Object UI Button A button will be added to the Scene Move it around as you would any object. Modify the button as you want Changing the Text is hidden away In the hierarchy panel open […]