Hello,
So for all I know there is something stupid simple that i may be overlooking, my game works. I have gone back and(at least with my one set of eyes) checked over the code in each video, up until the end of functions and encapsulation, as still my game will run without error and is perfect upon the first run, once the game ends and the number has been marked as correct with the return key, the game stays at the same guess number and does not reset? I am getting frustrated by this… but the urge to fix it and learn is stronger still… please help? my code is below…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NumberWizard : MonoBehaviour
{
int max;
int min;
int guess;
// Use this for initialization
void Start()
{
StartGame();
}
void StartGame()
{
max = 1000;
min = 1;
guess = 500;
Debug.Log("G'day mate, welcome to the numba wiz-ud...");
Debug.Log("Please pick a number, don't tell me what it is...");
Debug.Log("The highest number is: " + max);
Debug.Log("The lowest number is: " + min);
Debug.Log("Tell me if your number is higher or lower than: " + guess);
Debug.Log("Push Up = Higher, Push Down = Lower, Push Enter = Correct");
max = max + 1;
}
// Update is called once per frame
void Update()
{
// Detect when the up arrow key is pressed down
if (Input.GetKeyDown(KeyCode.UpArrow))
{
min = guess;
NextGuess();
}
// Detect when the down arrow key is pressed down
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
max = guess;
NextGuess();
}
// Detect when the return key is pressed down
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("I am a genius!");
}
}
void NextGuess()
{
guess = (max + min) / 2;
Debug.Log("Is it higher or lower than..." + guess);
}
}