Devin completed his first Unity program while taking the [Udemy Unity Course].
using UnityEngine;
using System.Collections;
public class NumberQizards : MonoBehaviour
{
int max = 1000;
int min = 1;
int guess;
// Use this for initialization
void Start()
{
StartGame();
}
void StartGame ()
{
print("Pick a number in your head but dont tell me.");
max = 1000;
min = 1;
guess = 500;
print("The highist number you can pick is " + max);
print("The lowest number you can pick is " + min);
NextGuess();
}
void NextGuess()
{
print("Is the number higher or lower then " + guess + "?");
print("Up arrow for higher , down arrow for lower");
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
min = guess;
guess = Mathf.FloorToInt((max + min) / 2f);
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
max = guess;
guess = Mathf.CeilToInt((max + min) / 2f);
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.Return))
{
print("You won!");
StartGame();
}
}
}