grid generation fault/error

hey guys,

I’m currently working on a project where I need to create a hexagon grid and place the hex tiles on it.
No problem creating the grid, but placing the tiles on that grid seems to not work as it should.
It’s supposed to place the tiles from left to right and then go down and place the next row, starting at 0,0,0.
So the first tile (0,0) should be at 0,0,0 and the next tile would be at 1,0,0. and then 2,0,0, etc.

Instead, it places the first column(0) all the way on the right and the first tile (0,0) is placed last, or is at least in what should be the last position.

here is the code that makes the grid and places the tiles:

void Generate_Grid(int row, int column)
{
	for (int y = 0; y < row; y++) 
	{
		for (int x = 0; x < column; x++)			
		{
			GameObject gameObject = Instantiate (Hexagon_Tile) as GameObject;
                        gameObject.name = "tile (" + x + "," + y + ")";
                        Hexagon_Tile.transform.position = new Vector3(x, z,y);
                         // i use x,z,y so that Z is up/down as normally used/done...
                }
         }
}

[I left out the code that actually makes the hex-grid]

I really don’t know why the tiles aren’t placed correctly, but they are ‘created’ in the proper order.
Also, sometimes “tile (0,0)” is placed at a wrong depth(y) all together…

If anybody could help me out here, that would be greatly appreciated!

bump

			GameObject gameObject = Instantiate (Hexagon_Tile) as GameObject;
                        gameObject.name = "tile (" + x + "," + y + ")";
                        Hexagon_Tile.transform.position = new Vector3(x, z,y);
                         // i use x,z,y so that Z is up/down as normally used/done...

Hexagon_Tile.transform.position = new Vector3(x, z,y);
You are instantiating a game object, but you are renaming the prefab, not the instantiated object. Is it normal ?

If you are using the prefab position to instantiate the prefab and place it properly when created, then this line is at the wrong place. Move it right before the instantiate because you need the prefab to be well positioned when you do it.

Plus, you are using gameObject for the variable name of your copy, but isn’t this keyword already being used to refer to the game object having the current script ?

akilae,

thank you for your respons.
I have now fixed it as such:

GameObject gameObject = Instantiate (Hexagon_Tile, new Vector3(x_pos, z_pos, y_pos), Quaternion.Identify) as GameObject;
				Tile_Script _tile = gameObject.GetComponent<Tile_Script> ();

the grid is now created and populated as I wanted it to.
It’s not exactly as you suggested, but it made me realise the mistake and then the solution.

so thank you