2016-04-15 89 views
-4

地鐵硬幣如何隨機遊戲aobject如地鐵硬幣團結如何隨機遊戲aobject如團結

void Start() { 
    game_over.text="Game Over"; 
    Ethan = GameObject.Find ("Ethan"); 
    coin = GameObject.Find ("coin"); 
    Vector3 position = new Vector3(Random.Range(15, 500), 0, Random.Range(10, 50)); 

    for (int i=0; i< Random.Range(10,555); i++) { 
     Instantiate (coin, position, Quaternion.identity); 
    } 
+1

這裏有問題嗎? –

+0

據我所知,我認爲這是某種教程?我在這裏看不到問題。 – Tom

+0

你不能把這個表達式「Random.Range(10,555)」放在一個foreach中。你必須說howMany = Random.Range(10,555),然後在比較中使用那個「howMany」。 – Fattie

回答

0

的任何for循環的第二部分必須是整數,因爲你不能循環通過幾分之一的時間。我會這樣做:

int iterations = Random.Range(10,555); 

print ("iterations = " + iterations);// this will show you what random integer was chosen 

for (int i=0; i< iterations; i++) { 
    Instantiate (coin, position, Quaternion.identity); 
}