Hello I am making a game where you chose a range of number then think of a number and then the computer figures out the number you are thinking of. However when I was trying to make It so you could chose the range of numbers I tested It and the keybinding isn’t working and I have tried quite a bit of stuff to make It work but to no avail so some help would be nice.
using UnityEngine;
using System.Collections;
public class Numblywizard : MonoBehaviour {
// Use this for initialization
int max;
int min;
int guess;
void Start () {
StartGame();
}
void StartGame () {
min = 1;
max = 500;
guess = Random.Range(min,max);
print ("==========================");
print ("Welcome to Number Wizard!");
print ("First you must chose the range in which you want me to pick a number");
print ("Press 1 for 1-100, 2 for 100-1000, 3 for 1-10000, 4 for 1000-10000, 5 for 1-100000, 6 for 10000-100000,7 for 1-1000000, and 8 for 100000-1000000");
if (Input.GetKeyDown(KeyCode.Alpha1)) {
max = 1000;
min = 1;
max = max + 1;
FirstGuess();
}else if (Input.GetKeyDown(KeyCode.Alpha2)) {
max = 1000;
min = 100;
max = max + 1;
FirstGuess();
}else if (Input.GetKeyDown(KeyCode.Alpha3)) {
max = 10000;
min = 1;
max = max + 1;
FirstGuess();
}else if (Input.GetKeyDown(KeyCode.Alpha4)) {
max = 10000;
min = 1000;
max = max + 1;
FirstGuess();
}else if (Input.GetKeyDown(KeyCode.Alpha5)) {
max = 100000;
min = 1;
max = max + 1;
FirstGuess();
}else if (Input.GetKeyDown(KeyCode.Alpha6)) {
max = 100000;
min = 10000;
max = max + 1;
FirstGuess();
}else if (Input.GetKeyDown(KeyCode.Alpha7)) {
max = 1000000;
min = 1;
max = max + 1;
FirstGuess();
}else if (Input.GetKeyDown(KeyCode.Alpha8)) {
max = 1000000;
min = 100000;
max = max + 1;
FirstGuess();
}
}
void FirstGuess() {
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 arrow = higher, down arrow = lower, Enter = When I have chosen the correct number");
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.UpArrow)) {
min = guess;
NextGuess();
}else if (Input.GetKeyDown(KeyCode.DownArrow)) {
max = guess;
NextGuess();
}else if (Input.GetKeyDown(KeyCode.Return)) {
print("I won!");
StartGame();
}
}
void NextGuess () {
guess = Random.Range(min,max);
print ("Higher or lower than " + guess);
print ("Up arrow = higher, down arrow = lower, Enter = When I have chosen the correct number");
Update();
}
}



