Answer the question
In order to leave comments, you need to log in
Checking the input of the desired number. Why does not it work?
I made a game with multiplication tables. An example is randomly generated and the player needs to enter the correct answer in a field (type: InputField ). The generation works, you can enter numbers in the field, but when you call the method for checking the correct answer from the script by pressing the button, nothing happens, I have been busy with this for a day, it would seem, a trifle, but how much hassle. Below is the script.
public class Maths : MonoBehaviour
{
[SerializeField] GameObject equationPanel;
[SerializeField] int firstNumber;
[SerializeField] int secondNumber;
[SerializeField] int answer;
[SerializeField] Text numText;
public InputField answerInput;
void Start()
{
equation();
//Debug.Log("Верно!");
}
public void equation()
{
int firstNumber = UnityEngine.Random.Range(0, 10);
int secondNumber = UnityEngine.Random.Range(0, 10);
string taskString = firstNumber + "x" + secondNumber;
numText.text = taskString;
answer = firstNumber * secondNumber;
}
public void checkAnswer()
{
int answerInt = Convert.ToInt32(answerInput);
if (answerInt == answer)
{
Debug.Log("Верно!");
}
else
{
Debug.Log("Неверно!");
}
equation();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question