Unity创建动态对象

时间:2015-04-23 19:22:00

标签: unity3d

如何在Unity中的代码中从一面墙到另一面创建动态对象(立方体)?这样: enter image description here

2 个答案:

答案 0 :(得分:3)

有趣的是,Unity家伙写了一个看起来与你想要达到的完全相同的例子:)

http://docs.unity3d.com/Manual/InstantiatingPrefabs.html

答案 1 :(得分:0)

您可以使用2实例化预制件。

public GameObject objToCreate;

void Start ()
{
    //2 for sentences to create a vidirectional array
    for(int i = 0; i<5;i++){            //for move on Y
        for(int j = 0; j<5;j++){        //for move on X
            Instantiate(objToCreate, transform.position,transform.rotation);
            transform.Translate(1f,0,0);    //Move on X
        }
        transform.Translate(0,1f,0);    //When fill X translate on Y and start again
        transform.Translate(-5f,0,0);   //Reset out transform position 5 units as set in the first for sentence
        //For mor space between objects just change the values in Translate function
    }
}