Make GUILayout horizontal first, then vertical? (C#)

By that I mean fill it’s horizontal first, then it’s vertical? I did a google search and found nothing, so I figured it would also be nice to be able to find it via google.

For instance I have this code, but it makes the items start filling vertically not horizontally.

	void OnGUI()
			int tempinv = 0;
			GUILayout.BeginArea (new Rect(40, 40, 500, 500));
			GUILayout.Box ("Weapons");
			foreach(GameObject items in inventory)
			if(GUILayout.Button (  new GUIContent(items.GetComponent<Item>().itemname,  items.GetComponent<Item>().itemname + "

" + items.GetComponent().currentWepType + "
" + items.GetComponent().dmg + " dmg
" + items.GetComponent().aspd + " seconds per attack"), GUILayout.Width (50), GUILayout.Height (50)))
Debug.Log ("Equipping " +;
Destroy (clone1);
toUpdate = true;
hasCloned = true;
clone1 = Instantiate(items, WepHolder.transform.position, WepHolder.transform.rotation) as GameObject;
clone1.transform.parent = GameObject.Find (“Main Camera”).transform;
clone1.SetActive (true);
Debug.Log ("You are now using: " +;
clone1.tag = “weaponEquipped”;
toUpdate = false;


		if(GUI.tooltip != null)
				GUILayout.Box (new GUIContent(GUI.tooltip), GUILayout.Height(67));
				GUI.tooltip = null;
		GUILayout.EndArea ();

Are you looking for GUILayout.BeginHorizontal and GUILayout.BeginVertical?

You can nest these to provide the effect you desire.

GUILayout.BeginVertical(); //Instead of hardcoding it, you can use a for()    loop to get multiple columns.
GUILayout.EndHorizontal(); //Remember to end each one!

Look here for more information.

The trick is to build the bigger area first. So make a wide space with a Horizontal, and then make several Verticals inside it. The verticals will “stack” horizontally (since they’re in a Horizontal). It’s tricky to get used to but once you do it’s pretty slick.

GUILayout.BeginHorizontal(); {
  GUILayout.BeginVertical(GUILayout.ExpandWidth(true)); {
    GUILayout.Label("Stacked 1");
    GUILayout.Label("Stacked 2");
  } GUILayout.EndVertical();
  GUILayout.BeginVertical("box", GUILayout.Width(200)); {
    GUILayout.Label("Squished 1");
    GUILayout.Label("Squished 2");
  } GUILayout.EndVertical();
} GUILayout.EndHorizontal();

@Dothackking Old question, but helped me answer itself. You use nested

functions, and a modulo (%) to set the number of columns.

This example is for making a Texture2DArray, so it uses an integer to set the number of textures, and gives you a field of texture slots matching that integer:

    int arraySize = 2; //Starting size of 2 images, can be adjusted by GUI field
    int arraySizeCheck; //Prevents the array from updating every frame and emptying
        Texture2D[] inputTextures; //Texture slots will automatically appear, disappear, and stack to match arraySize
        int arrayFieldWidth //This doesn't need to be its own value, I just use 4, this just shows the sorting math
        void OnGUI () {
        arraySize = EditorGUILayout.IntField ("Number of textures:", Mathf.Clamp(arraySize, 1, 36));
        		if (arraySizeCheck != arraySize) {
        			inputTextures = new Texture2D[arraySize];
        			arraySizeCheck = arraySize;
        //Get the window width so the array fits no matter the size
        EditorGUILayout.BeginVertical (GUILayout.MaxWidth (position.width));
        		for (int i = 0; i < arraySize; i++) {
        			if (i % arrayFieldWidth == 0)
        				EditorGUILayout.BeginHorizontal ();
        			inputTextures _= (Texture2D)EditorGUILayout.ObjectField ("Texture " + (i).ToString(), inputTextures*, typeof(Texture2D), false);*_
 _*			if (i != 0 && i % arrayFieldWidth == (arrayFieldWidth-1))*_
 _*				EditorGUILayout.EndHorizontal ();*_
 _*		}*_
 _*		EditorGUILayout.EndVertical ();*_
_*Hopefully this helps you or someone else out there!*_
_*(P.S. this isn't a complete script, just the few values and OnGUI() function.)*_