using UnityEngine;
using System.Collections;
public class Generation : MonoBehaviour {
void Start () {
for (int z = 1; z < 20; z++) {
for (int x = 1; x < 20; x++) {
//create cube
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
//add rigid body
cube.AddComponent<Rigidbody>();
//freze the y axis
cube.rigidbody.constraints = RigidbodyConstraints.FreezePositionY;
// create random color
Color newColor = new Color( Random.value, Random.value, Random.value, 1.0f );
//color cube
cube.renderer.material.color = newColor;
//create random number to add to y
int RandomAdd = Random.Range(1,6);
//create y
int y = 0;
//add number to y
y += RandomAdd;
//offset
cube.transform.position = new Vector3(x, y, z);
}
}
}
void Update () {
}
}
I am trying to create a game where the cubes randomly generate at random heights, so i can later on place procedural generated building on them, my blocks now do this : Screenshot - eed286ac4c82791fcd6c15edd2b9a46d - Gyazo
I would like them to not have the gaps so it is all connected, how can i do that ?