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.
64 lines
1.9 KiB
64 lines
1.9 KiB
1 year ago
|
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()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|