Skip to content

Instantly share code, notes, and snippets.

@tinyhappysteps
Last active December 7, 2015 14:44
Show Gist options
  • Save tinyhappysteps/679885b30825ed591833 to your computer and use it in GitHub Desktop.
Save tinyhappysteps/679885b30825ed591833 to your computer and use it in GitHub Desktop.
Unity basic script working - Number Wizard
using UnityEngine;
using System.Collections;
public class NumberWizards : MonoBehaviour {
int max = 1000;
int min = 1;
int guess = 500;
// Use this for initialization
void Start () {
print ("Welcome to Number Wizard");
print ("Pick a number in your head and don't tell me!");
print ("The highest number you can pick is " + max);
print ("The lowest number you can pick is " + min);
print ("Is the number higher or lower than " + guess);
print ("Up = higher, down = lower, return = equals");
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.UpArrow)) {
// print("up arrow pressed");
min = guess;
guess = (min + max) / 2;
print ("Is the number higher or lower than " + guess);
} else if (Input.GetKeyDown(KeyCode.DownArrow)) {
// print("down arrow pressed");
max = guess;
guess = (min + max) / 2;
print ("Is the number higher or lower than " + guess);
} else if (Input.GetKeyDown(KeyCode.Return)) {
print("I won!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment