using System.Collections; using System.Collections.Generic; using UnityEngine; public class WorldController : MonoBehaviour { public GameObject block; public int worldSize = 2; public int worldHeight = 2; // y public int worldWidth = 2; // x public int worldDepth = 2; // z public IEnumerator BuildWorld() { for(int z = 0; z < worldDepth; z++) for(int y = 0; y < worldHeight; y++) { for(int x = 0; x < worldWidth; x++) { // randomizes only the top layer if (y == worldHeight - 1 && Random.Range(0, 100) < 50) continue; // randomizes the top two layers if (y >= worldHeight - 2 && Random.Range(0, 100) < 50) continue; Vector3 pos = new Vector3(x, y, z); GameObject cube = GameObject.Instantiate(block, pos, Quaternion.identity); cube.name = x + "_" + y + "_" + z; /* My solution if(y == 0) { Vector3 pos = new Vector3(x, y, z); GameObject cube = GameObject.Instantiate(block, pos, Quaternion.identity); cube.name = x + "_" + y + "_" + z; } else if(Random.Range(0, 2) == 1 && y > 0) { Vector3 pos = new Vector3(x, y, z); GameObject cube = GameObject.Instantiate(block, pos, Quaternion.identity); cube.name = x + "_" + y + "_" + z; } */ } yield return null; } } // Start is called before the first frame update void Start() { StartCoroutine(BuildWorld()); } // Update is called once per frame void Update() { } }