Question by
liibanhassan13 · Apr 23, 2016 at 04:51 PM ·
number
Can somebody help me please?
using UnityEngine; using System.Collections;
public class NumberWizards : MonoBehaviour { // Use this for initialization int max; int min; int guess;
void Start () {
startgame();
}
void startgame () {
int max = 1000;
int min = 1;
int guess = 500;
max = max + 1;
print ("========================");
print ("Welcome to number wizard");
print ("Think of a number in your head, but dont tell me!");
print ("The highest number you can pick is" + max);
print ("The lowest Number you can is" + min);
print ("Is your number higher or lower than" + guess);
print ("Up = higher, lower = down, return = equal");
}
// 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!");
}
}
void nextguess () {
guess = (max + min) / 2;
print ("Higher or lower than" + guess);
print ("Up = higher, lower = down, return = equal");
}
}
Comment
Answer by SoundPuppy · Apr 23, 2016 at 05:03 PM
@liibanhassan13 keep your ints out side of voids
using UnityEngine;
using System.Collections;
public class NumberWizards : MonoBehaviour { // Use this for initialization int max; int min; int guess;
public int max = 1000;
public int min = 1;
public int guess = 500;
void Start () {
startgame();
}
void startgame () {
max = max + 1;
print ("========================");
print ("Welcome to number wizard");
print ("Think of a number in your head, but dont tell me!");
print ("The highest number you can pick is" + max);
print ("The lowest Number you can is" + min);
print ("Is your number higher or lower than" + guess);
print ("Up = higher, lower = down, return = equal");
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.UpArrow)) {
min = guess;
} else if (Input.GetKeyDown(KeyCode.DownArrow))
max = guess;
else if (Input.GetKeyDown(KeyCode.Return))
print("I won!");
}
void nextguess () {
guess = (max + min) / 2;
print ("Higher or lower than" + guess);
print ("Up = higher, lower = down, return = equal");
}
}
Your answer