Hello,
So after the player hits enter, confirming that the correct number has been guessed I would like a message to appear that says “Press Enter to Test My Skills Again!”. Then a second press of Enter would initiate a new game.
I can get the message to appear but the game just restarts without the need for an additional “Enter” input from the player. I believe the issue is that after the player presses Enter the first time, the next frame occurs and it starts looking for any input again as the void update() function starts over. I’m wondering how I can make the script pause after 1 key input of Enter, and wait for a second one before taking any further action? This is what I have so far, if anyone has any ideas I’d appreciate any feedback, Thank you.
void Start()
{
StartGame();
}
void StartGame()
{
max = 1000;
min = 1;
guess = 500;
Debug.Log("Welcome to Number Wizard Fellow Friend and Traveler.");
Debug.Log("Please Choose a Number Between " + min + " and " + max + "." + " But Don't Tell Me What it is!");
Debug.Log("Is Your Number is Higher or Lower Than " + guess + "?");
Debug.Log("Press Up if Your Number is Higher Than " + guess + ".");
Debug.Log("Press Down If your Numbers is Lower Than " + guess + ".");
Debug.Log("Press Enter When I Have Correctly Guessed Your Number.");
max = max + 1;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Debug.Log("So, Your Number is Higher Than " + guess + "...");
min = guess;
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
Debug.Log("So, Your Number is Lower Than " + guess + "...");
max = guess;
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("So I Finally Got it! Your Number Was " + guess + "!");
Debug.Log("Press Enter to Test My Skills Again.");
if (Input.GetKeyDown(KeyCode.Return))
StartGame();
}
}
void NextGuess()
{
guess = (max + min) / 2;
Debug.Log("Is Your Number " + guess + "?");
}
}