Hey! I’m pretty new to unity and I need help trying to create a cube pyramid using cube prefabs. So far, I’m able to create two-dimensional stairs using the following code and referencing the cube prefab to an empty game object:
using UnityEngine;
using System.Collections;
public class StepsBuilder : MonoBehaviour
{
public int height = 0;
public int width = 0;
public GameObject brickPrefab = null;
public int widthCounter = 0;
public int heightCounter = 0;
public GameObject awesomeBrick = null;
// Use this for initialization
void Start ()
{
while (heightCounter < height)
{
while (widthCounter < width)
{
awesomeBrick = (GameObject)Instantiate(brickPrefab);
awesomeBrick.transform.position = new Vector3(widthCounter, heightCounter, 0.0f);
widthCounter++;
}
widthCounter = heightCounter + 1;
heightCounter++;
}
}
// Update is called once per frame
void Update ()
{
}
}
This makes a staircase that, depending on what the user sets the width and height to, looks basically like this (* == cube):
Now I need to basically work backwards so the steps go back down to make a two-dimensional pyramid but, where do I go from here? I’ve tried multiple things, but to no avail. I’m unfortunately completely stuck. Thanks in advance for the help!