- Home /
first button click not working,first button click isn't working
i'm writing a game where the game guesses a random number the player is thinking. i have the guess higher and guess lower fields wired up to the buttons in the inspector. no matter which button you click first, it doesnt work until you click it again.
public class GameLogic : MonoBehaviour { [SerializeField] int min; //sets intial lowest number [SerializeField] int max; //sets initial highest number int randomNumber; //is the first guess from the computer
public void StartGame()
{
min = 0;
max = 1000;
NextGuess();
}
public void GuessHigher() //called when higher button is pressed
{
min = randomNumber+1; //sets new low to the random number
NextGuess(); //calls next guess method
}
public void GuessLower() //called when lower button is pressed
{
max = randomNumber-1; //sets new high to the random number
NextGuess(); //calls next guess method
}
public void NextGuess()
{
randomNumber = Random.Range(min, max); //generates next guess
Debug.Log("random is " + randomNumber + " low is " + min + " high is " + max); //debug log
}
Your answer
Follow this Question
Related Questions
I really need a JumpPad script for a JumpPad in unity 2D 0 Answers
Is there a better way to tell when enemies are dead? 2 Answers
C# Yield in a Method with Return a value 1 Answer
Unable to unhinge and hing a new object. 0 Answers
How add Compontent B to all Childs with Component A (e.g. Script) 1 Answer