Unity Tile-Based Ground

Tile-Based Ground – Unity3D (C#)

To create a tile-based ground, we need a simple matrix system. A (row X column) matrix will take a plane texture and draw it in each cell.

public GameObject plane;
public int width = 10;
public int height = 10;

private GameObject[,] grid = new GameObject[30, 30];

void Start () {
 for (int x =0; x < width; x++) {
  for (int y =0; y < height; y++){
   GameObject gridPlane = (GameObject)Instantiate(plane);
   gridPlane.transform.position = new Vector2(gridPlane.transform.position.x + x, 
                gridPlane.transform.position.y + y);
   grid[x, y] = gridPlane;
  }
 }
}

Tile-Based Ground – Unity3D (C#)