我目前正在创建一款教育游戏来帮助人们学习数学,但我遇到了一个问题。
我随机化了一些立方体中的文本,玩家点击这些立方体来测试他们对倍数的了解,但是我目前使用的代码使得它偶尔在屏幕上没有正确答案,有没有办法我可以解决这个问题吗?
代码:
按钮
using UnityEngine;
using System.Collections;
public class RNG : MonoBehaviour
{
public GUIText thisAnswer;
public RandomiseAll reRoll;
int randomNumber = 0;
int miniScore = 0;
// Use this for initialization
void Awake ()
{
randomNumber = Random.Range (0, 36);
thisAnswer.text = randomNumber.ToString ();
}
void OnMouseUpAsButton ()
{
if (randomNumber % 3 == 0) {
miniScore += 100;
reRoll.Randomise ();
Debug.Log (miniScore.ToString ());
} else if (randomNumber % 3 != 0) {
reRoll.Randomise ();
Debug.Log (miniScore.ToString ());
}
}
全局重新随机化
using UnityEngine;
using System.Collections;
public class RandomiseAll : MonoBehaviour {
public GUIText[] answer;
int randomNumber;
int[] test;
public void Randomise(){
for (int i = 0; i < answer.Length; i++) {
randomNumber = Random.Range (0, 36);
answer [i].text = randomNumber.ToString ();
}
}
}
如有任何帮助,我们将不胜感激。
请您参考如下方法:
为什么不把正确答案和一堆其他随机的错误答案一起添加呢?
