Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jamora · Mar 04, 2014 at 11:14 PM 0
Share

Study the unity GUI scripting guide. Specifically the Layout $$anonymous$$odes.

Namely, you need to nest your BeginHorizontal and BeginVertical calls appropriately.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges