随机函数

时间:2016-03-28 05:13:56

标签: c# unity3d

所以我有生成随机例子的函数,但我需要这个函数也是随机的。提前谢谢;)

public void generateExample()
{
    x = Random.Range(0, 10);
    y = Random.Range(0, 10 - x);
    _text.GetComponent<TextMesh>().text = x.ToString() + " + " + y.ToString() + " =";
    resultNum = x + y;

}

public void generateExample2()
{

    x = Random.Range(0, 10);
    y = Random.Range(0, x);
    _text.GetComponent<TextMesh>().text = x.ToString() + " - " + y.ToString() + " =";
    resultNum = x - y;
}

1 个答案:

答案 0 :(得分:0)

y = new Random();
x = y.Range(0, 1);

if (x == 0)
{
  generateExample();
}
else if (x == 1)
{
  generateExample2();
}