如何将地铁硬币等游戏对象随机化

时间:2016-04-15 14:22:30

标签: unity3d

如何将地铁硬币等游戏对象随机化

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 :(得分: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);
}