using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class NumberWizard : MonoBehaviour {
// Use this for initialization
int max;
int min;
int guess;
int maxGuessesAllowed;
public Text text;
public Text guessesLeft;
void Start () {
StartGame ();
}
void StartGame () {
max = 1000;
min = 1;
guess = 500;
max = max + 1;
maxGuessesAllowed = 10;
}
void NextGuess () {
guess = (max + min) / 2;
maxGuessesAllowed = maxGuessesAllowed - 1;
text.text = guess.ToString();
guessesLeft.text = maxGuessesAllowed.ToString();
if(maxGuessesAllowed<=0){
Application.LoadLevel("Win");
}
}
public void GuessHigher(){
min = guess;
NextGuess ();
}
public void GuessLower(){
max = guess;
NextGuess ();
}
}
guessesLeft.text = maxGuessesAllowed.ToString(); returns a NullReferenceException when I try to use it. I’ve basically copied the functionality of the text.text object that updates the current computer guess. text.text works fine, but my guessesLeft.text throws the nullref.
Any idea what I’m doing wrong?