Hi my name is David, and I am from Bridlington in East Yorkshire. Below is my take on the solution. Hope you like it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NumberWizard : MonoBehaviour
{
int max = 1000;
int min = 1;
int guess = 500;
// Use this for initialization
void Start()
{
Debug.Log("Welcome to Number Wizard");
Debug.Log("Please pick a number, but don't tell me what it is....");
Debug.Log("The highest number you can pick is: " + max);
Debug.Log("The lowest number you can pick 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))
{
Debug.Log("So your number is higher than " + guess);
min = guess;
guess = (max + min) / 2;
Debug.Log("Is your number " + guess);
}
//Detect when the down arrow key is pressed down
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
Debug.Log("Sayin your number is lower than " +guess );
max = guess;
guess = (max + min) / 2;
Debug.Log("Is your number " + guess);
}
//Detect when the Return key is pressed down
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("Your number is:- " + guess + " Got there in the end. Easy");
}
}
}