Tile-Based Ground – Unity3D (C#)


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[,] gridd = 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);
				gridd[x, y] = gridPlane;
			}
		}
	}

©Coffee Break Codes – Tile-Based Ground – Unity3D (C#)


Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “Tile-Based Ground – Unity3D (C#)