2016-03-28 182 views
0

所以我有函數產生隨機的例子,但我需要這個函數也是隨機的。在此先感謝;)隨機函數

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

ü要隨機撥打這兩個功能?請calarify –

+1

這有可能幫助你嗎? http://stackoverflow.com/questions/1785744/how-do-i-seed-a-random-class-to-avoid-getting-duplicate-random-values – Tal

+0

是的,我想這兩個函數是隨機的 – SoManyQuestions

回答

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

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

謝謝你很多;)忘了把它放在void更新中,所以它只產生+例子。謝謝你,你真的幫了我 – SoManyQuestions