Why menu isn't working?

I don’t see any syntax that would cause “menu” to not change greeting back to "Hello " in that first condition… in fact menu isn’t resolving to true in that first condition no matter what the code is… am I overlooking an error in my code?

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

public class Hacker : MonoBehaviour
{ 
    // Variables
    string greeting = "Hello ";
    string NameToSend = "Heath";

    // Code
    void Start()
    {
        ShowMainMenu(NameToSend);
    }
    
    void ShowMainMenu(string NameToUse)
    {
        Terminal.ClearScreen();
        Terminal.WriteLine(greeting + NameToUse);
        Terminal.WriteLine(" ");
        Terminal.WriteLine("How would you like to proceed?");
        Terminal.WriteLine(" ");
        Terminal.WriteLine("1. easy peasey");
        Terminal.WriteLine("2. I'm going to jail");
        Terminal.WriteLine(" ");
        Terminal.WriteLine("Enter your selection:"); 
    }

    void OnUserInput(string input)
    {
        if (input == "menu")
        {
            greeting = "Hello ";
            ShowMainMenu(NameToSend);
        }
        if (input == "1")
        {
            Terminal.WriteLine("You chose lvl 1...");
        }
        else if (input == "2")
        {
            Terminal.WriteLine("You chose lvl 2...");
        }
        else if (input == "007")
        {
            NameToSend = "Mr. Bond";
            Terminal.WriteLine("You have a license to kill...");
        }
        else
        {
            greeting = "Please make a vaild choice ";
            ShowMainMenu(NameToSend);
        }
    }

}

The last else was being reached and resetting “greeting” because the second if conditional did not start with else, so it was a separate if else check… problem solved by adding else to second if

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

Privacy & Terms