Making a wall of cubes

[7061-untitled-1+copy.jpg|7061]

I’m trying to create a wall of cubes with this code,
but for some reason its skipped the first spot and start it into second with the “0-0”
like in the the image
.

 float cubeWidth = 0.98f;
 float cubeHeight = 0.98f; 
   void Start()
      {
            GameObject cube = new GameObject();

           -- reference for the next instances

            float referenceX = -2.938817f;
            float referenceY = -2.109755f;
            float referenceZ = 3.623962e-05f;

            for (int i = 0; i <= 5; i++)
                {
                  for (int j = 0; j <= 6; j++)
                     {
                       Vector3 position_ = new Vector3(referenceX + 
                       j * cubeWidth, referenceY + i * cubeHeight, 0);

                       cube.transform.position = position_;
                       cube = GameObject.CreatePrimitive(PrimitiveType.Cube);  

                        --show their names
                       cube.name = "" + i + "-" + j;
                      } 
                }   
      }

You are setting the position in the transform before you are creating the cube. The first time through the loop, no cube object exists. In all other passes through the loop, you are setting the position of the previous cube before you create the new cube. Swap these two lines, and everything should work.

cube = GameObject.CreatePrimitive(PrimitiveType.Cube); 
cube.transform.position = position_;

You’re setting the cube position before creating it! Swap the lines where you define the cube position and create the cube primitive:

        for (int i = 0; i <= 5; i++){
            for (int j = 0; j <= 6; j++){
                Vector3 position_ = new Vector3(referenceX + 
                 j * cubeWidth, referenceY + i * cubeHeight, 0);
                // create the cube first...
                cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                // and then set its position:
                cube.transform.position = position_;
                --show their names
                cube.name = "" + i + "-" + j;
            }