[Solved] My computer is not loosing any game (never stops guessing the number)

I am trying to solve the issue but I am not able to do that. My program is not terminating after number of guesses I asked to make. please help in this regard. below is the code.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class NumberWizard : MonoBehaviour {
// Use this for initialization
int max;
int min;
int guess;

public int MaxGuessAllow=5;
public Text text;
void Start () {
	StartGame();
}
void StartGame () {
	max = 1000;
	min = 1;
	guess = 500;
	max = max + 1;
}

public void GuessHigher(){
	min = guess;
	NextGuess();
}
public void GuessLower(){
max = guess;
NextGuess();
}


public void NextGuess () {
	guess = (max + min) / 2;
	text.text = guess.ToString ();
	MaxGuessAllow = MaxGuessAllow-1;
	if (MaxGuessAllow <= 0) {
		Application.LoadLevel("Win");
	}
}

}

1 Like

Well, the only thing that I think that can be causing this error is the public accessibility level, whatever you put in the inspector will override the initial value.

But a good way to discover the problem is to print the MaxGuessAllow value everytime you run the NextGuess() method. just add Debug.Log("MaxGuessAllow value is: " + MaxGuessAllow); bellow the text.text = guess.ToString(); and check what it prints to the console

You could also change the inspector mode to Debug mode by clicking on the cog wheel on the top of the inspector and selecting Debug. This will allow you to see the values of every variable within the script.

2 Likes

Did it worked @Fzlurrehman ? xD

1 Like

Yup, Thanks Alot

2 Likes

Privacy & Terms