Grid of blocks

I attached this code to an empty gameobject and am not sure why my block prefabs are not spawning. I’ve gotten it to work in previous games I’ve created but am confused why it no longer works in new games. I must be doing something wrong.

var block1 : GameObject; 
var index : int = 0;
var worldWidth :uint  = 500;
var worldHeight : uint  = 500;

function Start () {

CreateWorld();


}


function Update () {
}


function CreateWorld() {
    
    
        for(var x : uint =0; x<worldWidth; x+=25) {
        
        Debug.Log("SPAWN1");
        
       
      
         for(var z : uint =0; z<worldHeight; z+=25) {
         
          Debug.Log("SPAWN2");
       
          var block = Instantiate(block1);
          block.transform.position = new Vector3(x, block.transform.position.y , z - 20);
          
          
          }
          
          
          
          }
          
          }

I see nothing wrong with the code. Things to check:

  • Select the game object this script is attached to in the inspector and make sure that this script is attached and that the block1 variable has been assigned/initialized.
  • Since the other variables are public, make sure they have reasonable values in the inspector. Having worldWidth or worldHeight set to 0 would be a problem for example.
  • Drag the prefab into the scene to absolutely sure it is setup correctly (i.e. it is visible and does not cause any errors).
  • You are spawning your blocks at the position of the prefab as it was created, not at the position of the empty game object this script is attached to. Make sure that is what you want, that the prefab position is in view of the camera.
  • Check the hierarchy after this script as run to see if blocks were created.

Make sure that you have a GameObject from your hierarchy / project folder dragged onto the block1 variable for the GameObject containing your script.