My level is not changing like on the lecture

In the lecture i have seen that ben’s level changes to 0 when he presses “menu”. and it changes to 2 when he presses “2”, and changes to 1 if he presses “1”. How is that possible?

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

public class Hacker : MonoBehaviour {

    //Game Configuration Data
  
    string[] level1Passwords = { "banana", "shake", "Basel", "Hasan", "Code", "sleep" };
    string[] level2Passwords = { "milk", "I'm Batman", "Jarvis", "Gamedev", "Dani" }; 
    // Game state 
    int level;  
   enum Screen { MainMenu, Password, Win};
    Screen currentScreen;
    string password;
    // Start is called before the first frame update
    void Start()
    {
        ShowMainMenu("Hello User!");

        print(level1Passwords[3]);

    }
    void ShowMainMenu (string greeting)
    {
        currentScreen = Screen.MainMenu;
        Terminal.ClearScreen();
        
        Terminal.WriteLine(greeting);
        Terminal.WriteLine("What Would you like to hack into?");
        Terminal.WriteLine("Press 1 For a School (Easy)");
        Terminal.WriteLine("Press 2 for a Police Station (Medium)");
        

        Terminal.WriteLine("Enter your selection:");

        // A String is "" to any length | Eg. "Enter your Password"
        //boolean can be true or false 
        //Int (Integers) Are any number from -2,147,483,648 to +2,147,483,647
        //Floating point value (it's the decimal point that is floating) | Eg. Health, Speed, etc.| They are from +1.5e-45 to +3.4e38
        //Screen it's used for keepig track of which screen we are on in the game | Eg. Main menu, password, Win, etc.

    }

    void OnUserInput(string input)
    {
        void OnUserInput(string input)
        {
            Debug.Log("password: " + password); 
            Debug.Log("input: " + input);

            // rest of your code
        }
        // TODO handle differently depending on screen 

       if (input == "menu") 
        {
            ShowMainMenu("Hello Again, It's time to choose");
        }
        else if (currentScreen == Screen.MainMenu)
        {
            RunMainMenu(input);
        }
        else if (currentScreen == Screen.Password) ;
        {
            CheckPassword(input);

        }
    }

    void RunMainMenu(string input)
    {
        bool isValidLevelNumber = (input == "1" || input == "2");
        if (isValidLevelNumber)
        {
            level = int.Parse(input);
            StartGame();
        }




         


        else if (input == "Hasan Is The Best") // easter egg ;)
        {
            Terminal.WriteLine("Indeed he is, Now Choose!");

        }
        else if (input == "Bla bla bla") // easter egg
        {
            Terminal.WriteLine(" I Don't say Bla Bla Bla !");

        }

        else
            Terminal.WriteLine("Choose a level!");
    }

    void ShowMainMenu()
    {
        Terminal.WriteLine("Invalid Password.");
     }                       
    void StartGame()
    {

       
       currentScreen = Screen.Password;

        Terminal.ClearScreen();
        switch(level)
        {
            case 1:
                password = level1Passwords[4];
                break;
            case 2:
                password = level1Passwords[0];
                break;
            default:
                Debug.LogError("Invalid level number");
                break;
        }
        Terminal.WriteLine("Please Enter Your Password.");
    }

    void CheckPassword(string input)
    {
        if (input == password)
        {
            Terminal.WriteLine("WELL DONE!");
        }
        else
        {
            ShowMainMenu();
        }
    }




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


Hi Fullfi,

Is your Inspector set to “Debug” mode? Also make sure to select the active game object in your Hierarchy because that’s the one Unity is accessing and modifying during runtime.

Did this help?


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms