Skip to content

Instantly share code, notes, and snippets.

@cwilldev46
Created October 7, 2017 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwilldev46/91c468fe9d901431f142d5e67633e38f to your computer and use it in GitHub Desktop.
Save cwilldev46/91c468fe9d901431f142d5e67633e38f to your computer and use it in GitHub Desktop.
Number Wizard Script
using UnityEngine;
using System.Collections;
public class NumberWizard : MonoBehaviour {
// Use this for initialization
int max = 1000;
int min = 1;
int guess = 500;
void Start () {
StartGame();
}
void StartGame () {
//max = max + 1;
print ("Welcome to Number Wizard");
print ("Pick a number in your head, but don't tell me");
print ("The highest number you can pick is " + max);
print ("The lowest number you pick is " + min);
print ("Is the number higher or lower than " + guess);
print ("Up = higher, down = lower, or return = equal");
max = max + 1;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.UpArrow)) {
//print("Up arrow pressed");
min = guess;
NextGuess();
} else if (Input.GetKeyDown(KeyCode.DownArrow)) {
//print("Down arrow pressed");
max = guess;
NextGuess();
} else if (Input.GetKeyDown(KeyCode.Return)) {
print("I won!");
}
}
void NextGuess () {
guess = (max + min) / 2;
print ("Higher or lower than " + guess + "?");
print ("Up = higher, down = lower, or return = equal");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment