Creating Level Menu

Operating System
First create a new scene by pressing ctrl + n then save it in the scene directory as "Level Menu". Set the component value of the canvas as shown below.

Level Menu UI

Next create a image and new canvas will be created at the same time. Then rename the canvas as "Level Menu UI" and the image as "Background" tut30 Then for the Image tut31

Level Buttons

Now that we have the background we will now add the buttons that will proceed as to next level. First create a new GameObject called it Level Button Holder this will hold all the buttons. After that create a buttons(15) as a children of the newly created GameObject. Next is to add Image inside the button and set it component as shown below. tut32 And for the Text just enter an increment number that correspond to your level selection. Once your done make sure it the same as shown below. tut33

Creating Level Menu Controller

Now that we have the level menu ui, we will now create the Level Menu Controller just like what we did on the main menu. The Level Menu Controller handles the selection for the stages. To this just simply create a new GameObject name it as Level Menu Controller, then create a script and name it LevelMenuController. Inside the Level Menu Controller script, create a certain variable that we will use. Write these variables inside the Main Menu Controller class.
  1. public bool[] levels;
  2. public Button[] levelButtons;
Then add this several methods to your script.
  1. // Use this for initialization
  2.     void Start () {
  3.         InitilizeGameVariables ();
  4.     }
  5.    
  6.     // Update is called once per frame
  7.     void Update () {
  8.         if(Input.GetKeyDown(KeyCode.Escape)){
  9.             SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex - 1);
  10.         }
  11.     }
  12.  
  13.     void InitilizeGameVariables(){
  14.         if(GameController.instance != null){
  15.             levels = GameController.instance.levels;
  16.  
  17.             for (int i = 1; i < levels.Length; i++) {
  18.                 if (levels [i]) {
  19.                     levelButtons [i].transform.GetChild (1).transform.gameObject.SetActive (false);
  20.                 } else {
  21.                     levelButtons [i].interactable = false;
  22.                 }
  23.             }
  24.         }
  25.  
  26.     }
  27.  
  28.     public void LevelSelect(){
  29.         string level = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name;
  30.  
  31.         switch(level){
  32.         case "Level 1":
  33.             if(GameController.instance != null){
  34.                 GameController.instance.currentLevel = 1;    
  35.             }
  36.         break;
  37.  
  38.         case "Level 2":
  39.             if(GameController.instance != null){
  40.                 GameController.instance.currentLevel = 2;    
  41.             }
  42.             break;
  43.  
  44.         case "Level 3":
  45.             if(GameController.instance != null){
  46.                 GameController.instance.currentLevel = 3;    
  47.             }
  48.             break;
  49.  
  50.         case "Level 4":
  51.             if(GameController.instance != null){
  52.                 GameController.instance.currentLevel = 4;    
  53.             }
  54.             break;
  55.  
  56.         case "Level 5":
  57.             if(GameController.instance != null){
  58.                 GameController.instance.currentLevel = 5;    
  59.             }
  60.             break;
  61.  
  62.         case "Level 6":
  63.             if(GameController.instance != null){
  64.                 GameController.instance.currentLevel = 6;    
  65.             }
  66.             break;
  67.  
  68.         case "Level 7":
  69.             if(GameController.instance != null){
  70.                 GameController.instance.currentLevel = 7;    
  71.             }
  72.             break;
  73.  
  74.         case "Level 8":
  75.             if(GameController.instance != null){
  76.                 GameController.instance.currentLevel = 8;    
  77.             }
  78.             break;
  79.  
  80.         case "Level 9":
  81.             if(GameController.instance != null){
  82.                 GameController.instance.currentLevel = 9;    
  83.             }
  84.             break;
  85.  
  86.         case "Level 10":
  87.             if(GameController.instance != null){
  88.                 GameController.instance.currentLevel = 10;    
  89.             }
  90.             break;
  91.  
  92.         case "Level 11":
  93.             if(GameController.instance != null){
  94.                 GameController.instance.currentLevel = 11;    
  95.             }
  96.             break;
  97.  
  98.         case "Level 12":
  99.             if(GameController.instance != null){
  100.                 GameController.instance.currentLevel = 12;    
  101.             }
  102.             break;
  103.  
  104.         case "Level 13":
  105.             if(GameController.instance != null){
  106.                 GameController.instance.currentLevel = 13;    
  107.             }
  108.             break;
  109.  
  110.         case "Level 14":
  111.             if(GameController.instance != null){
  112.                 GameController.instance.currentLevel = 14;    
  113.             }
  114.             break;
  115.  
  116.         case "Level 15":
  117.             if(GameController.instance != null){
  118.                 GameController.instance.currentLevel = 15;    
  119.             }
  120.             break;
  121.  
  122.         }
  123.  
  124.         SceneManager.LoadScene (level);
  125.            
  126.     }
After that attach the script to the Level Menu Controller GameObject, then also attach all the necessary Objects in the script. tut34

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment