Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement