Hello, I tried this:
void Start () {
int i = 0;
int j = 0;
for (i = 0; i < 30; i++)
for(j = 0 ; j<20; j++)
createbox(i, j);
}
private void createbox(float x, float y)
{
GameObject box = GameObject.CreatePrimitive(PrimitiveType.Cube);
box.name = "cube" + x.ToString() + y.ToString();
box.transform.position = new Vector3(x*1.02f+1, y*1.02f, 0);
BoxCollider bc = box.AddComponent("BoxCollider") as BoxCollider;
}
But unity is giving me
Can’t add component ‘BoxCollider’ to cube01 because such a component is
already added to the game object!