Making A 3D Maze Game in Unity - 9/10

Now we are going to make a main menu for our game . Our main menu will contain a play button and a quit button. Play button will take us to the game scene and quit button will make the game quit. You can make multi level selection panel if you want. In that case you may set a play button and when the player press it we will show a level selection panel.

For now we will make the gamre with ine level. We will make a menu manager script to handel scene managment.

Fist save the game level scene we just made and name it "level_1". now open a new scene. we are going to make a main menu panel like pause panel. you can use buttons for all of your features here. For now i am just setting a play button.

Fist make a canvas in the hierachy and set it in this setting.

9.1.PNG

now make a button in the canvas.

GameObject>UI>Button

adjust its size position from the rect transform component.

9.3.PNG

You may change the image of your button from Image component.

9.4.PNG

name it as play button. then make an empty game object named menu Manager. creat a new c# script name it menuManager. attach the script with the menu manager game object. open menuManager in mono behaviour. then copy paste this script and save it.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
public class menuManager : MonoBehaviour {
 public string LevelName;
 
// Use this for initialization
 void Start () {

    

 }

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


public void goTo()
{
    SceneManager.LoadScene (LevelName);
}
    


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

}

after saving this script we will some variables in the script from the inspector.

9.2.PNG

In the level variableof menu manager, write the level name you want to go by pressing play button. connect the button with goTo() function of menuManager.

AUTHOR

READ NEXT

Boostlog is an online community for developers
who want to share ideas and grow each other.

Delete an article

Deleted articles are gone forever. Are you sure?