public class NumberWizard : MonoBehaviour {
// definition
static int max = 1000;
static int min = 1;
static int guess = (min + max) / 2;
const string HIGHER = "higher";
const string LOWER = "lower";
// Use this for initialization
void Start () {
Debug.Log("Welcome to number wizard");
Debug.Log("Pick a number between " + min + " and " + max + " :");
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++;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.UpArrow)) {
min = guess;
PrintResult(HIGHER);
} else if (Input.GetKeyDown(KeyCode.DownArrow)) {
max = guess;
PrintResult(LOWER);
} else if (Input.GetKeyDown(KeyCode.Return)) {
Debug.Log("Your guess was: " + guess + "!");
}
}
void PrintResult(string higherOrLower) {
guess = (min + max) / 2;
Debug.Log("Your guess was " + higherOrLower);
Debug.Log("Tell me if your number is higher or lower than " + guess);
Debug.Log("Push Up = higher, Push Down = Lower, Push Enter = Correct");
}
}