- Home /
 
 
               Question by 
               amilo1003 · Mar 04, 2014 at 11:08 PM · 
                guimonodevelopguilayoutbeginscrollview  
              
 
              GUILayout.BeginScrollView how to create new row?
So i have scroll view and i have to create new row for it, it is all in one row so it has too much empty space
 using UnityEngine;
 using System.Collections;
 
 public class GUIEleveation : MonoBehaviour {
 
     public GUISkin skin;
 
     public string name;
     string hardnessLabel;
 
     bool textFieldTextRemoved;
 
     public Texture2D w1, w2, w3, w4, m1, m2, m3, m4, w1t, w2t, w3t, w4t, m1t, m2t, m3t, m4t, w1d, w2d, w3d, w4d, m1d, m2d, m3d, m4d;
     public Texture2D[] flags;
 
     public Material selectedFlag;
 
     public Vector2 scroll;
 
     public int progress;
     public int hardness;
     int count;
     void OnGUI () {
         GUI.skin = skin;
 
         switch (progress) {
 
         case 0:
             // Name Panel
             GUI.Box(new Rect(Screen.width /2-200,Screen.height /2-200,400,400),"User Info");
             GUI.SetNextControlName("nameTextField");
             name = GUI.TextField(new Rect(Screen.width/2-150, Screen.height/2-33.3f, 300, 50), name, 20);
             if (Input.GetMouseButtonDown(0) && GUI.GetNameOfFocusedControl() == "nameTextField" && !textFieldTextRemoved) {
                 name = "";
                 textFieldTextRemoved = true;
             }
             if (GUI.Button(new Rect(Screen.width/2-150, Screen.height/2+100, 300, 50), "Next")) {progress = 1;}
             break;
 
         case 1:
             // Portret Select
             GUI.Box(new Rect(Screen.width/2-400,Screen.height/2-300,800,600),"Select your Race");
             GUILayout.BeginArea(new Rect(Screen.width/2-400,Screen.height/2-270,800,600));
             GUILayout.BeginHorizontal();
             GUILayout.FlexibleSpace();
             if (GUILayout.Button(w1,"Box",GUILayout.Height(180),GUILayout.Width(180)))
             {
                 m1 = m1d;
                 m2 = m2d;
                 m3 = m3d;
                 m4 = m4d;
                 w1 = w1t;
                 w2 = w2d;
                 w3 = w3d;
                 w4 = w4d;
             }
             GUILayout.FlexibleSpace();
             if (GUILayout.Button(w2,"Box",GUILayout.Height(180),GUILayout.Width(180)))
             {
                 m1 = m1d;
                 m2 = m2d;
                 m3 = m3d;
                 m4 = m4d;
                 w1 = w1d;
                 w2 = w2t;
                 w3 = w3d;
                 w4 = w4d;
             }
             GUILayout.FlexibleSpace();
             if (GUILayout.Button(w3,"Box",GUILayout.Height(180),GUILayout.Width(180)))
             {
                 m1 = m1d;
                 m2 = m2d;
                 m3 = m3d;
                 m4 = m4d;
                 w1 = w1d;
                 w2 = w2d;
                 w3 = w3t;
                 w4 = w4d;
             }
             GUILayout.FlexibleSpace();
             if (GUILayout.Button(w4,"Box",GUILayout.Height(180),GUILayout.Width(180)))
             {
                 m1 = m1d;
                 m2 = m2d;
                 m3 = m3d;
                 m4 = m4d;
                 w1 = w1d;
                 w2 = w2d;
                 w3 = w3d;
                 w4 = w4t;
             }
             GUILayout.FlexibleSpace();
             GUILayout.EndHorizontal();
             GUILayout.EndArea();
 
             GUILayout.BeginArea(new Rect(Screen.width/2-400,Screen.height/2-75,800,600));
             GUILayout.BeginHorizontal();
             GUILayout.FlexibleSpace();
             if (GUILayout.Button(m1,"Box",GUILayout.Height(180),GUILayout.Width(180)))
             {
                 m1 = m1t;
                 m2 = m2d;
                 m3 = m3d;
                 m4 = m4d;
                 w1 = w1d;
                 w2 = w2d;
                 w3 = w3d;
                 w4 = w4d;
             }
             GUILayout.FlexibleSpace();
             if (GUILayout.Button(m2,"Box",GUILayout.Height(180),GUILayout.Width(180)))
             {
                 m1 = m1d;
                 m2 = m2t;
                 m3 = m3d;
                 m4 = m4d;
                 w1 = w1d;
                 w2 = w2d;
                 w3 = w3d;
                 w4 = w4d;
             }
             GUILayout.FlexibleSpace();
             if (GUILayout.Button(m3,"Box",GUILayout.Height(180),GUILayout.Width(180)))
             {
                 m1 = m1d;
                 m2 = m2d;
                 m3 = m3t;
                 m4 = m4d;
                 w1 = w1d;
                 w2 = w2d;
                 w3 = w3d;
                 w4 = w4d;
             }
             GUILayout.FlexibleSpace();
             if (GUILayout.Button(m4,"Box",GUILayout.Height(180),GUILayout.Width(180)))
             {
                 m1 = m1d;
                 m2 = m2d;
                 m3 = m3d;
                 m4 = m4t;
                 w1 = w1d;
                 w2 = w2d;
                 w3 = w3d;
                 w4 = w4d;
             }
             GUILayout.FlexibleSpace();
             GUILayout.EndHorizontal();
             GUILayout.EndArea();
 
             if (GUI.Button(new Rect(Screen.width/2-150,Screen.height/2+200,300,50),"Next")) {progress = 2;}
             break;
 
         case 2:
             // Flag Selection
             GUI.Box(new Rect(Screen.width/2-400, Screen.height/2-300, 800, 600),"Flag");
             GUILayout.BeginArea(new Rect(Screen.width/2-375,Screen.height/2-245,750,450));
             scroll = GUILayout.BeginScrollView(scroll);
             foreach (Texture2D flag in flags) {
                 if(GUILayout.Button(flag, "Box", GUILayout.Width(90), GUILayout.Height(90))) {selectedFlag.mainTexture = flag;}
             }
             GUILayout.EndScrollView();
             GUILayout.EndArea();
             if (GUI.Button(new Rect(Screen.width/2-150, Screen.height/2+233.33f, 300, 50), "Next")) {progress = 3;}
             break;
 
         case 3:
             // Main Menu
             GUI.Box(new Rect(Screen.width/2-200, Screen.height/2-150, 400, 250), "Main Menu");
             GUILayout.BeginArea(new Rect(Screen.width/2-150, Screen.height/2-75, 300, 150));
             if (GUILayout.Button("Start Game", GUILayout.Width(300), GUILayout.Height(50))) {}
             GUILayout.FlexibleSpace();
             if (GUILayout.Button("Options", GUILayout.Width(300), GUILayout.Height(50))) {progress = 4;}
             GUILayout.EndArea();
             break;
 
         case 4:
             //Options
             GUI.Box(new Rect(Screen.width/2-350, Screen.height/2-300, 700, 600), "Options");
             GUILayout.BeginArea(new Rect(Screen.width/2-325, Screen.height/2-225, 650, 450));
             GUILayout.Label("Difficulty");
             hardness = (int)GUILayout.HorizontalSlider(hardness, 1, 3);
             GUILayout.Label(hardnessLabel);
             GUILayout.Space(30);
             if (GUILayout.Button("Reset Progress", GUILayout.ExpandWidth(true))) {PlayerPrefs.DeleteAll();}
             GUILayout.EndArea();
             if (Input.GetMouseButtonUp(0)) {
                 PlayerPrefs.SetInt("Hardness", (int)hardness);
             }
             if (GUI.Button(new Rect(Screen.width/2-150, Screen.height/2+200, 300, 50), "Back")) {progress = 3;}
             break;
 
         }
     }
 
     void Start () {
         hardness = PlayerPrefs.GetInt("Hardness");
     }
 
     void Update () {
         if (progress == 4) {
             switch (hardness) {
             case 1:
                 hardnessLabel = "Easy";
                 break;
             case 2:
                 hardnessLabel = "Medium";
                 break;
             case 3:
                 hardnessLabel = "Hard";
                 break;
             }
         }
     }
 }
 
               Thanks
               Comment
              
 
               
              Study the unity GUI scripting guide. Specifically the Layout $$anonymous$$odes.
Namely, you need to nest your BeginHorizontal and BeginVertical calls appropriately.
Your answer
 
             Follow this Question
Related Questions
How to disable horizontal scrollbar in GUILayout scroll view? 3 Answers
Drawing several BeginArea inside a BeginScrollview (GUILayout) produces an unexpected behaviour 1 Answer
Setting Scroll View Width GUILayout 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Coin Counting Problem 0 Answers