Terminal Hacker project Question (Udemy Unity Course)

Hello All!

I have a bug in my code that I do not understand:
In Unity, it says:

Unity is calling for a curly bracket, but there are no curly brackets missing…

Here’s my code:

using UnityEngine;

public class Hacker : MonoBehaviour
{

    string[] level1Passwords = {"connection", "router", "watch", "play", "stream", "load"};
    string[] level2Passwords = { "Masterpiece", "Borrow", "recive", "Checkout", "script", "character" };

    //Game State
    int level;
    enum Screen { MainMenu, Password, Win };
    Screen currentScreen;
    string password;

    // Start is called before the first frame update
    void Start()
    {

        ShowMainMenu();
    }

    void Update()
    {
        int index = Random.Range(0, level1Passwords.Length);
        print(index);
    }

    void ShowMainMenu()
    {
        Screen currentScreen = Screen.MainMenu;
        Terminal.ClearScreen();
        Terminal.WriteLine("What would you like to hack into?");
        Terminal.WriteLine("Press 1 for the WIFI");
        Terminal.WriteLine("Press 2 for the Library");
        Terminal.WriteLine("Selection: ");
    }

    void OnUserInput(string input)
    {
        if (input == "menu")
        {
            ShowMainMenu();
        }
        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(level);
        }
        else if (input == "pogchamp")
        {
            Terminal.WriteLine("You're my little pogchamp");
        }
        else
        {
            Terminal.WriteLine("Please choose a valid level");
        }


    }

    void StartGame(int level)
    {
        print(level1Passwords.Length);
        print(level2Passwords.Length);
        currentScreen = Screen.Password;
        Terminal.ClearScreen();
        switch (level)
        {
            //Can't type here
            case 1:
                int index1 = Random.Range(0, level1Passwords.Length);
                password = level1Passwords[index1];
                break;
            case 2:
                int index2 = Random.Range(0, level2Passwords.Length);
                password = level2Passwords[index2];
                break;
            default:
                Debug.LogError("Invalid Level Number");
                break;
        }
        Terminal.WriteLine("Please enter your Password: ");
    }

    void CheckPassword(string input)
    {
        if (input == password)
        {
            DisplayWinScreen();
        }
        else
        {
            Terminal.WriteLine("Wrong! Try again...");
        }
    }
    void DisplayWinScreen()
    {
        currentScreen = Screen.Win;
        Terminal.ClearScreen();
        ShowLevelRewards();
    }
    void ShowLevelRewards()
    {
        switch (level)
        {
            case 1:
                Terminal.WriteLine("Have a book...");
                break;

        }
    }
    


Try adding a curly bracket at the very end of your file. It looks like you’re missing the closing bracket for your class.

1 Like

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

Privacy & Terms