I'm building a simple calculator app in unity. My variable firstNumber is assigned a value but is getting set to zero when the Equal method is called. I can't figure out what is setting it back to zero. I've added a screenshot of the Unity Console to help explain.
private TextMesh inputBox;
private double firstNumber;
private char operation = '+';
void Start()
{
inputBox = (TextMesh)GameObject.Find("InputBox").GetComponent<TextMesh>();
}
public void nOne()
{
if (inputBox.text == "0" && inputBox.text != null)
{
inputBox.text = "1";
}
else
{
inputBox.text += "1";
}
}
public void Add()
{
firstNumber = double.Parse(inputBox.text);
Debug.Log("First num " + firstNumber);
operation = '+';
Debug.Log(operation);
inputBox.text = "0";
}
public void Equal()
{
double secondNumber;
double result;
Debug.Log("First Number: " + firstNumber);
secondNumber = double.Parse(inputBox.text);
Debug.Log("Second Number: " + secondNumber);
result = firstNumber + secondNumber;
Debug.Log("Sum: " + result);
}