02-Number-Wizard-Console icon indicating copy to clipboard operation
02-Number-Wizard-Console copied to clipboard

Only restarts once?

Open SteveLunny opened this issue 3 years ago • 0 comments

Hi there

My code seems to match yours. I can play the game, and restart it once but after that it doesn't respond anymore. Any idea what might be wrong

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

public class NumberWizard : MonoBehaviour { int maxGuess; int minGuess; int guess;

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

void StartGame()
{
    maxGuess = 1000;
    minGuess = 1;
    guess = 500;
    Debug.Log("Welcome to Number Wizard, eh!");
    Debug.Log("Pick a number from 1 to 1000! Do eeet!");
    Debug.Log("Don't go higher than " + maxGuess);
    Debug.Log("Don't go lower than " + minGuess);
    Debug.Log("Tell me if your number is higher or lower than my guess, " + guess);
    Debug.Log("Push UP if your number is higher. Push DOWN if you number is lower. Push ENTER if it's correct!");
    maxGuess = maxGuess + 1;
}


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

    if (Input.GetKeyDown(KeyCode.UpArrow))
    {
        minGuess = guess;
        NextGuess();
    }

   else if (Input.GetKeyDown(KeyCode.DownArrow))
    {
        maxGuess = guess;
        NextGuess();

    }

    else if (Input.GetKeyDown(KeyCode.Return))
    {
        Debug.Log("I got it! I'm amazing xo.");
        StartGame();
    }
}

void NextGuess()
{
    guess = (maxGuess + minGuess) / 2;
    Debug.Log("Is it higher or lower than " + guess);
}

}

SteveLunny avatar Jul 12 '20 21:07 SteveLunny