我想創建使用統一3d學習目的的怪胎數學應用程序。 我看不到在下面的源代碼中調用的隨機數學函數。onclick按鈕功能似乎並沒有調用randommath函數
當我點擊播放按鈕我可以得到隨機數字,但是一旦我點擊了真正的按鈕或假按鈕,我沒有看到隨機數字函數被調用。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GameControllerScript : MonoBehaviour
{
public Text MathText;
public Text ResultText;
private int rightNumber;
private int leftNumber;
private int TrueResultNumber;
private int FalseResultNumber;
void Start()
{
RandomMath();
}
void RandomMath()
{
rightNumber = Random.Range (0, 10);
leftNumber = Random.Range (0, 10);
int mOperator = Random.Range (0,2);
switch (mOperator) {
case 0:
TrueResultNumber = leftNumber + rightNumber;
MathText.text = leftNumber.ToString() + "+" + rightNumber.ToString();
FalseResultNumber = TrueResultNumber + Random.Range (-2, 2);
ResultText.text = "=" + FalseResultNumber.ToString();
break;
case 1:
TrueResultNumber = leftNumber + rightNumber;
MathText.text = leftNumber.ToString() + "-" + rightNumber.ToString();
FalseResultNumber = TrueResultNumber + Random.Range (-2, 2);
ResultText.text = "=" + FalseResultNumber.ToString();
break;
case 2:
TrueResultNumber = leftNumber + rightNumber;
MathText.text = leftNumber.ToString() + "*" + rightNumber.ToString();
FalseResultNumber = TrueResultNumber + Random.Range (-2, 2);
ResultText.text = "=" + FalseResultNumber.ToString();
break;
default:
break;
}
}
public void OnTrueButtonClick()
{
if (TrueResultNumber == FalseResultNumber) {
RandomMath();
}
else {
}
}
public void OnFalseButtonClick()
{
if (TrueResultNumber != FalseResultNumber) {
RandomMath();
} else {
}
}
}