So I had switched the max number of guesses from 10 to 5 and then back to 10 again, but my game still thinks that number is 5. I put some console statements to debug and noticed that it was saying:
5 max guesses
4 remaining guesses
3 remaining guesses
2 remaining guesses
1 remaining guesses
0 remaining guesses
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class NumberWizard : MonoBehaviour
{
private int _guess;
private int _max;
private int _min;
private int _remainingGuesses;
public int MaxGuessesAllowed = 10;
public Text Text;
private void Start()
{
StartGame();
}
private void StartGame()
{
_max = 1000;
_min = 1;
_guess = (_max + _min) / 2;
_max = _max + 1;
_remainingGuesses = MaxGuessesAllowed;
}
public void GuessHigher()
{
_min = _guess;
NextGuess();
}
public void GuessLower()
{
_max = _guess;
NextGuess();
}
private void NextGuess()
{
_guess = (_min + _max) / 2;
Text.text = _guess.ToString();
_remainingGuesses--;
Debug.Log(MaxGuessesAllowed + " max guesses");
Debug.Log(_remainingGuesses + " remaining guesses");
if (_remainingGuesses <= 0) SceneManager.LoadScene("Win");
}
}