[Solved] Clicking Higher sometimes lower the first guess value

Hello, so I’ve randomized both guess and initial value number, and I noticed sometimes when I play, and click Higher first time in the game, the second number is actually lower than first guessed value. In example program asks if Number is Higher or Lower than 507, I click Higher and it shows 305 then. The functions are correctly linked into my buttons, so I think it’s not that. What’s wrong in my C# code? Thanks for answer

public class NumberWizard : MonoBehaviour {
	int min,max,guess;
	int MaxGuessesNumber;
	public Text text;
	
	void Start () {	
		StartGame();
	}
	
	void StartGame () {
		max = 1000;
		min = 1;
		MaxGuessesNumber=12;
		NextGuess();
	}
	public void GuessHigher(){
		min = guess;
		NextGuess();
	}
	
	void GuessLower(){
		max = guess;
		NextGuess();
	}
	void NextGuess () {
		guess = Random.Range (min,max+1);
		text.text = "Is it number "+guess.ToString ()+ "\nor is it higher / lower?";
		MaxGuessesNumber=MaxGuessesNumber-1;
		if (MaxGuessesNumber<=0) { Application.LoadLevel ("Win");}
	}
	
	
	public void Lost() {
		Application.LoadLevel ("Lose");
	}

Pics:

Edit:

Sorry, I actually found answer on that forum… I somehow got this wrong during the lessons, so I attached NumberWizard.cs script both into new Game Obejct (Number Wizard) and then Text object. While text object was already connected with .cs file in Game Object. So guess was called twice in Start(). Sorry for this topic

Privacy & Terms