Fun little introductory thing to some aspects we are gonna be working with. Looking forward to this. I am sure there is more that I could be doing with this. I need to fix it so it doesnt repeat the guess three times when asking you…
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 = (min + max) / 2;
Debug.Log("Imagine! The Fantastic Number Wizard WILL guess your number");
Debug.Log("Pick a Number, any number...");
Debug.Log("Okay not any number...");
Debug.Log("The highest is: " + max);
Debug.Log("The lowest is: " + min);
Debug.Log("Tell Me if your number is higher or lower than " + guess);
Debug.Log("Push up if it's Higher, Push down if it's Lower, Push Enter if I got the number");
max = max + 1;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Debug.Log("Ah, aiming for the stars");
min = guess;
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
Debug.Log("I see you think less of me");
max = guess;
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("Your number was " + guess);
Debug.Log("Hah,I knew it");
StartGame();
}
}
void NextGuess()
{
guess = (max + min) / 2;
Debug.Log("Is it higher or lower than... " + guess);
}
}