Editor Script to create Pyramid from basic shapes in unity3d

You might have seen my previous post "How to create a staircase using editor scripts in Unity".
Here you find a script to create a pyramid like structure.

All you have to follow the procedure to create the basic building block of pyramid. In staircase I used a cube like structure as basic building block. This time I am using a capsule with some texture applied over it.
My capsule looks like:

Now the same procedure as Stairs, Just replace the script with the following one.
Script name: PyramidGenerator.cs
The script I have written is in C#. the class extends Editor Window class of Unity. We do not need any extra plugin to run this script but while placing it in the project , you need to place it in "Editor" folder.
The script is as follows.

using UnityEngine;
using UnityEditor;
using System.Collections;

public class PyramidGenerator : EditorWindow {
public GameObject cratePrefab;//prefab of building block
GameObject crate,Pyramid;//building blocks and final pyramid
int pyrHeight;//height or number of layers
float offset=0.25f;
[MenuItem("Pyramid/Create Pyramid")]//menu to show the window
public static void ShowWindow()
void OnGUI()
//Enter the height and basic block's reference
pyrHeight=EditorGUILayout.IntField("Height of Pyramid :",pyrHeight);
cratePrefab =(GameObject)EditorGUILayout.ObjectField("Base Game Object :",cratePrefab, typeof(GameObject), true);

//Create the pyramid
Pyramid=new GameObject("Pyramid");
for(int pyrLength=pyrHeight*2;pyrLength>0;pyrLength--)
for(int pyrWidth=pyrHeight*2;pyrWidth>0;pyrWidth--)
crate=GameObject.Instantiate(cratePrefab,new Vector3(0,0,0),Quaternion.identity)as GameObject;
crate.transform.position=new Vector3(pyrLength+offset,crate.transform.position.y+offset,pyrWidth+offset);"Crate";

//Create the top most block
crate=GameObject.Instantiate(cratePrefab,new Vector3(0,0,0),Quaternion.identity)as GameObject;"Crate";
crate.transform.position=new Vector3(crate.transform.position.x,crate.transform.position.y+offset,crate.transform.position.z);
crate.transform.position=new Vector3(crate.transform.position.x+offset,crate.transform.position.y,crate.transform.position.z+offset);


And if you create pyramid of height 10, it 'll look like,

So, Friends this is how you can create a pyramid using an editor script in unity3d.

For any comments and suggestions please write to me in the following comment box..
I make no money out of this blog. The purpose of writing this blog is only to display my skills