So I wanted to change a little bit of coding there, after the game asks, the highest number and the lowest number that you can select is, I wanted the game to ask if the user is ready, so i wrote a code to ask the user if you have thought of the number and asked the user to press leftcontrol if he is ready. The problem that i am facing now is that it works fine for once, but when the game restarts, it stops at the point where the game asks user to press left control.
This is my code:
int max;
int min;
int guess;
void Start ()
{
StartGame ();
}
void StartGame() {
max=1000;
min=1;
guess=500;
print ("***************************");
print ("welcome to Numberwizard");
print ("pick a number in your head but don't tell me");
print ("The highest number you can select is " + max);
print ("The lowest number you can select is " + min);
print ("press leftcontrol if you have selected");
max=max+1;
}
void NextGuess()
{
guess = (max + min)/2;
print ("higher or lower than " + guess);
}
void Update () {
if (Input.GetKeyDown(KeyCode.LeftControl))
{
print ("Is your number higher or lower than " + guess);
print ("Up arrow for higher, down for lower, return for equal");
}
if (Input.GetKeyDown(KeyCode.UpArrow))
{
//print("Up arrow key pressed");
min = guess;
NextGuess ();
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
//print("Down arrow key pressd");
max = guess;
NextGuess ();
}
else if (Input.GetKeyDown(KeyCode.Return))
{
print ("I won!");
StartGame ();
}
}
}