Does anybody know how Unity says 1 + 0 = 10?
I have a simple math question with an input field which include the question:" 1 + 0 = ?"
If the result is right then it will be return right and if it false then it returns false.
Now when I input 1 in the textField it return right. But when I write 10 it returns right too.
P.S. I change the string value from the textField to an integer with “int.Parse(inputField1.text);”.
Here is my whole Script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SimpleAddition : MonoBehaviour {
public Text number1;
public Text number2;
public Text resultOfNumber1AndNumber2;
public InputField inputField1;
public int value1;
public int value2;
public int resultValue;
public int ownResultValue;
public bool right = false;
public GameObject right; //GamObject with a Text "right"
public GameObject false;
void Start()
{
wert1 = Random.Range(0, 5);
wert2 = Random.Range(0, 5);
number1.text = value1.ToString();
number2.text = value2.ToString();
result.text = "???";
resultValue = Addition(value1, value2);
}
public int Addition(int number1, int number2)
{
int summe = number1 + number2;
return summe;
}
void Update()
{
ownResultValue = int.Parse(inputField1.text);
if (resultValue== ownResultValue)
right = true;
}
public void CheckResult()
{
if (right)
{
right.SetActive(true);
false.SetActive(false);
}
if (!right)
{
false.SetActive(true);
right.SetActive(false);
}
}
}
The method “CheckResult” is called from a button when you are done.