If the user cheats, doesn’t pay attention, or otherwise presses the wrong button for Higher or Lower, the min value could be greater than the max value (because of adding and subtracting 1 to get Random.Range() to work properly, I guess?) And the guesses get wonky.
The nice thing about [SerializeField] is that I could preset my min and max for debugging, like min=780 and max=781 and watching the Inspector values change while pressing the buttons. VERY COOL!
Not sure if this is the best way, but I think I fixed it with the following code, so it doesn’t change the guess value when it runs into the above situation.
public void OnPressHigher()
{
if (min < max)
{
min = guess + 1;
NextGuess();
}
}
public void OnPressLower()
{
if (min < max)
{
max = guess - 1;
NextGuess();
}
}
void NextGuess()
{
if (min < max + 1)
{
guess = Random.Range(min, max + 1);
guessText.text = guess.ToString();
}