Created
April 8, 2019 23:34
-
-
Save DB-009/932bb2b47a74193bf0b920860c7122d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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