Hey. So earlier in the course, I was having issues with the CheckPassword function, despite following along with the video multiple times and checking my code against the current logs code, it kept giving me errors in Unity, saying that it “doesn’t exist in the current context”.
Eventually, I decided that it was probably something that would get fixed later in the course, I’m about to start the win screen one now and I have several more issues than what I started with, and I have no idea what to do.
My code and the issues are below, any help or advice would be appreciated.
using UnityEngine;
public class TerminalHacker : MonoBehaviour
{
//Game Configuration Data
string[] level1Passwords = { "flora", "fauna", "water", "grass", "birch" };
string[] level2Passwords = { "beaker", "periodic", "iodine", "mercury", "bismuth" };
//remember level 3 passwords!!!
// Game state
int level;
enum Screen { MainMenu, Password, WinState };
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()
{
currentScreen = Screen.MainMenu;
Terminal.ClearScreen();
Terminal.WriteLine("Welcome to The Royal Liberty Museum");
Terminal.WriteLine("Which facility will you hack into?");
Terminal.WriteLine("Press 1 to hack the Nature Wing");
Terminal.WriteLine("Press 2 to hack the Science Wing");
Terminal.WriteLine("Press 3 to hack the Fine Arts Wing");
Terminal.WriteLine("Please enter your 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();
}
else
{
Terminal.WriteLine("Please Select a Valid Option");
}
void StartGame() //add hints
{
currentScreen = Screen.Password;
Terminal.Clearscreen();
switch(level)
{
case 1:
password = level1Passwords[Random.Range(0, level1Passwords.Length)];
break;
case 2:
password = level2Passwords[Random.Range(0, level2Passwords.Length)];
break;
default:
Debug.LogError("Invalid Selection");
break;
}
Terminal.WriteLine("You have selected Wing " + level);
Terminal.WriteLine("Please enter the password:");
}
void CheckPassword(string input)
{
if (input == password)
{
Terminal.WriteLine("Correct Password");
}
else
{
Terminal.WriteLine("Incorrect!");
}
}
}
}