You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class GridGeneration : MonoBehaviour
{
[SerializeField] private int _width, _height;
[SerializeField] private Tile _tilePrefab;
public Material[] tileTextures;
// Start is called before the first frame update
public void GenerateGrid() {
if (_tilePrefab == null)
{
Debug.LogError("No Tile prefab found. Please insert prefab in field.");
return;
}
var tileParent = new GameObject("Tile Parent").transform;
for (int x = 0; x < _width; x++) {
for (int z = 0; z < _height; z++){
var tileBound = _tilePrefab.GetComponent<Renderer>().bounds.size;
Debug.Log(x+tileBound.x + z+tileBound.z);
var spawnedTile = Instantiate(_tilePrefab, new Vector3(x*tileBound.x, 0, z*tileBound.z), Quaternion.identity, tileParent);
spawnedTile.name = $"Tile {x} {z}";
spawnedTile.GetComponent<Tile>().myManager = this.gameObject;
}
}
}
//void Hiearchy(){
// var hierarchyDiv = new GameObject("--- Level ---").transform;
// }
}