Unity Community


Results 1 to 6 of 6

  1. Posts
    164

    Generate Level Select Menu

    Hey guys, I'm trying to make a level select menu that is easily editable. I have it working in one column, but I want to be able to make it expand over a number of columns because I have a lot of levels.

    This is what I have so far...
    Code:  
    1. var numberOfLevels : int;
    2. private var levelChoice : String;
    3.  
    4. function levelList() {
    5.     for(var n = 1; n < numberOfLevels; n++){
    6.         var height = 35 * n;
    7.         if (GUI.Button (Rect (Screen.width/2-50, 100 + height, 100, 30), "Level " + n)) {
    8.             levelChoice = "Level" + n;
    9.             loadLevel();
    10.         }
    11.     }
    12. }


  2. Location
    Denton, TX, USA
    Posts
    174
    Code:  
    1.            // For this example, we are using an array of GUIContent items.
    2.             GUIContent[] items = new GUIContent[100];
    3.             // We must create an index variable to track our location in the GUIContent array.
    4.             int index = 1;
    5.             // We also need to know how many items can appear in one row.
    6.             int xCount = 10;
    7.             // We use a while loop in case there are no items to draw.
    8.             while (index < items.Length)
    9.             {
    10.                 // Begin a Row
    11.                 GUILayout.BeginHorizontal();
    12.                 // Use a for loop to create the row contents
    13.                 for (int x = 0; x < xCount; x++)
    14.                 {
    15.                     // If the index is greater than the array size,
    16.                     if (index >= items.Length)
    17.                         // end the for loop.
    18.                         break;
    19.                     // Otherwise, create a button for the item at the current index,
    20.                     // and increase the index by one.
    21.                     GUILayout.Button(items[index++]);
    22.                 }
    23.                 // End a Row
    24.                 GUILayout.EndHorizontal();
    25.             }
    26.         }

    This is how I create a multicolumn list of controls. You can put your while loop inside of an Area you define with a Rect.
    Build UnityGUIs faster, with new features! Sketch GUI
    Build UnityGUIs faster for free (VERY obsolete/unsupported)! EWS GUI Editor Free Edition.
    Build levels faster! Asset+ 3.5.1.
    Better workflow in SceneView with new SceneView Context Menu.
    Better GUISkin Inspector!


  3. Posts
    164
    Quote Originally Posted by EddyEpic View Post
    Code:  
    1.            // For this example, we are using an array of GUIContent items.
    2.             GUIContent[] items = new GUIContent[100];
    3.             // We must create an index variable to track our location in the GUIContent array.
    4.             int index = 1;
    5.             // We also need to know how many items can appear in one row.
    6.             int xCount = 10;
    7.             // We use a while loop in case there are no items to draw.
    8.             while (index < items.Length)
    9.             {
    10.                 // Begin a Row
    11.                 GUILayout.BeginHorizontal();
    12.                 // Use a for loop to create the row contents
    13.                 for (int x = 0; x < xCount; x++)
    14.                 {
    15.                     // If the index is greater than the array size,
    16.                     if (index >= items.Length)
    17.                         // end the for loop.
    18.                         break;
    19.                     // Otherwise, create a button for the item at the current index,
    20.                     // and increase the index by one.
    21.                     GUILayout.Button(items[index++]);
    22.                 }
    23.                 // End a Row
    24.                 GUILayout.EndHorizontal();
    25.             }
    26.         }

    This is how I create a multicolumn list of controls. You can put your while loop inside of an Area you define with a Rect.
    I'll give it a try! Thanks!


  4. Posts
    164
    I came up with this code which works pretty well.
    Code:  
    1.     for(var n=1; n < maxAllowedLevel;){
    2.         for(var i=0; i<nomRows; i++){
    3.             for(var j=0;j<nomCols; j++){
    4.                 GUI.enabled = n <= maxAllowedLevel;
    5.                 if(GUI.Button(new Rect(Screen.width/2 - screenAdjust + i*80,j*30 + 150,buttonWidth,25),"Level " + n)){
    6.                     //Load level N
    7.                 }
    8.             n++;
    9.             }   
    10.         }
    11.     }


  5. Location
    Brazil
    Posts
    220
    Quote Originally Posted by xKroniK13x View Post
    I came up with this code which works pretty well.
    Code:  
    1.     for(var n=1; n < maxAllowedLevel;){
    2.         for(var i=0; i<nomRows; i++){
    3.             for(var j=0;j<nomCols; j++){
    4.                 GUI.enabled = n <= maxAllowedLevel;
    5.                 if(GUI.Button(new Rect(Screen.width/2 - screenAdjust + i*80,j*30 + 150,buttonWidth,25),"Level " + n)){
    6.                     //Load level N
    7.                 }
    8.             n++;
    9.             }   
    10.         }
    11.     }
    Thats basic Matrix handling =D


  6. Posts
    150
    i did something similar which is like a grid of small buttons, and it makes an object the with and height of the button click's width and height, for example 4th one up in first row will make the object 4 heigh 1 wide

    Code:  
    1. //GRID SELECTOR 
    2.  
    3.     for (var b7:int = 0; b7 < 36; b7 ++)    {
    4.     var sz = 12;
    5.     if (GUI.Button (Rect(b7*12% 72+240,Mathf.Floor(-b7*12/72)*12+72,12,12),GUIContent("b7","fast selection for digger size")))
    6.         {
    7.             Wt=(b7%6)+1;   Ht=(Mathf.Floor(b7/6))+1;
    8.         }//+++++++++++++++++++++++++++++++++++++++++  
    9.     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •