Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TileMapGenerator : MonoBehaviour
  6. {
  7.  
  8. public int xTiles, zTiles, yTiles;//basic length,width,height variable to do math on how many total tiles to cerate
  9. public GameObject tilePrefab;//prefab of basic tile were creating
  10. public Transform spawnPosition;//original position of where tiles get created to
  11. // Start is called before the first frame update
  12.  
  13. public void Start()
  14. {
  15. //GenerateMapInital();
  16. }
  17.  
  18. public void GenerateMapInital()
  19. {
  20. int xPos=0, zPos=0, yPos=0;
  21. for(int tilePos = 0; tilePos < (xTiles*zTiles)*yTiles;tilePos++)//length*height gives area of square yTiles will be used later to add floors/layers
  22. {
  23. GameObject tileObject = GameObject.Instantiate(tilePrefab, spawnPosition.position + new Vector3(xPos, yPos, zPos), Quaternion.identity);//instatiate the tile
  24. tileObject.transform.SetParent(this.transform);//set it as a child of this object to clear cluter
  25. xPos++;//increase XPos so tiles get spawned to different position
  26. if(xPos >= xTiles)//if XPos reached limit reset it to 0 and increase zPos
  27. {
  28. xPos = 0;
  29. zPos++;
  30. }
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement