Adding multiple objects and colliders.

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!

Just remove that line of code, and run your game, find the “box” you created in the hierarchy, click on it and you will see in the inspector that unity has added a box collider to your box automatically, and that’s why you can’t add one!