Skip to content

Instantly share code, notes, and snippets.

@DB-009
Created April 8, 2019 23:34
Show Gist options
  • Save DB-009/932bb2b47a74193bf0b920860c7122d3 to your computer and use it in GitHub Desktop.
Save DB-009/932bb2b47a74193bf0b920860c7122d3 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TileMapGenerator : MonoBehaviour
{
public int xTiles, zTiles, yTiles;//basic length,width,height variable to do math on how many total tiles to cerate
public GameObject tilePrefab;//prefab of basic tile were creating
public Transform spawnPosition;//original position of where tiles get created to
// Start is called before the first frame update
public void Start()
{
//GenerateMapInital();
}
public void GenerateMapInital()
{
int xPos=0, zPos=0, yPos=0;
for(int tilePos = 0; tilePos < (xTiles*zTiles)*yTiles;tilePos++)//length*height gives area of square yTiles will be used later to add floors/layers
{
GameObject tileObject = GameObject.Instantiate(tilePrefab, spawnPosition.position + new Vector3(xPos, yPos, zPos), Quaternion.identity);//instatiate the tile
tileObject.transform.SetParent(this.transform);//set it as a child of this object to clear cluter
xPos++;//increase XPos so tiles get spawned to different position
if(xPos >= xTiles)//if XPos reached limit reset it to 0 and increase zPos
{
xPos = 0;
zPos++;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment