Hey everyone, here’s my take on the Number Wizard:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class NumberWizard : MonoBehaviour
{
int max = 1000;
int min = 1;
int guess = 500;// Start is called before the first frame update void Start() { StartGame(); } void StartGame() { Debug.Log("Wazzzuuup! I'm gonna totally guess the number you are thinking"); Debug.Log("Pick a number from " + max + " to " + min); Debug.Log("My guess is:" + guess); Debug.Log("Press Up arrow if your number higher, press Down arrow if lower. Push Enter if my guess is 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; guess = (max + min) / 2; Debug.Log("Oh man, I'm so low.. Alright is it: " + guess + "?"); } //Detect when the down arrow key is pressed down else if (Input.GetKeyDown(KeyCode.DownArrow)) { max = guess; guess = (max + min) / 2; Debug.Log("Oh man, I'm so high right now.. Alright, is it: " + guess + "?"); } //Detect when the Return arrow key is pressed down else if (Input.GetKeyDown(KeyCode.Return)) { Debug.Log("Eyyyy we got there in the end. Fun times"); } }
}