Cube Pyramid

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! :slight_smile:

You need to offset the start of each row by half a block * row number (minus 1)

Would you care to elaborate? Sorry.

try this. You should really calculate the height from the width as a user might enter a height greater than the width and depending on what the brick prefab is this could cause problems, maybe make the height = width. Anyway this almost works:

    using UnityEngine;
    using System.Collections;
     
    public class PyramidBuilder : MonoBehaviour
    {
        public int height = 0;
        public int width = 0;
        public GameObject brickPrefab = null;
        public GameObject awesomeBrick = null;
        public float xpos=0.0f;
     
        // Use this for initialization
        void Start ()
        {
		for(int i = 0; i < height; i++)
		{
			for(int j = 0; j < width; j++)
			{
				awesomeBrick = (GameObject)Instantiate(brickPrefab);
                awesomeBrick.transform.position = new Vector3(j+xpos, i, 0.0f);
			}
			width-=2; // remove 2 bricks from the width
			xpos++; // shift the start position of next row along 1 block can use 0.5 to shift half a block
		}
        }
       
        // Update is called once per frame
        void Update ()
        {
       
        }
    }

void Pyramid(int pNum)
{
for (int y = 0; y < pNum; y++)
{
for (int z = 0; z < pNum-y; z++)
{
for (int x = 0; x < pNum-y; x++)
{
temp = Instantiate(box, new Vector3(x + tNum, y, z + tNum),Quaternion.identity);
}
}
tNum += .5f;
}

}