I need help in making a GUI layout scroll view

if(isinoptions == 8){

var data : HostData[] = MasterServer.PollHostList();
    // Go through all the hosts in the host list
    scrollPos = GUILayout.BeginScrollView (scrollPos, false/*alwaysShowHoriz*/, true /*alwaysShowVert*/);  //@@
    for (var element in data)
    {
        var elementPing:Ping=Ping(element.ip.ToString());
        var elementPingUIValue:String=elementPing.ToString();
        GUILayout.BeginHorizontal();    

        GUILayout.Space(20);
        var name = element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit+" Ping:" +elementPingUIValue;
        GUILayout.Label(name);  
        GUILayout.Space(5);
        var hostInfo;
        hostInfo = "[";
        for (var host in element.ip)
            hostInfo = hostInfo + host + ":" + element.port + " ";
        hostInfo = hostInfo + "]";
        GUILayout.Label(hostInfo);  
        GUILayout.Space(5);
        GUILayout.Label(element.comment);
        GUILayout.Space(5);
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Connect"))
        {
            connectStatus="Connecting";

            Network.Connect(element.ip, element.port);          
        }

        GUILayout.EndScrollView();
        GUILayout.EndHorizontal();  
    }
if (data.length>0){
serverFoundStatus=data.length+" Servers Found";
}
if (data.length==0){
serverFoundStatus="No public servers found yet";
}
GUI.Label(Rect(25,240,600,300),connectStatus);
GUI.Label(Rect(25,280,600,300),serverFoundStatus);
if (GUI.Button (Rect (25,220,100,20), "Refresh List")) {
connectStatus="Refreshing Master server list on ip :"+MasterServer.ipAddress;
MasterServer.ClearHostList();
MasterServer.RequestHostList("StealthReduxCoop");
}
if (GUI.Button (Rect (125,220,50,20), "Back")){
isinoptions=0;
}

}

I wanted to make a serverlist and used a scrollview in which i dont have much experience and the result is crashing.What am i doing wrong? Also , how can i make the scrollview have these coordinates (20,20,Screen.width-20,200)

Edit: Oh come on , its been over 2 weeks

You’re calling “GUILayout.EndScrollView();” inside your for loop. It should be outside.

So it should be more like this…

  • BeginScrollView
  • For loop and whatever you want inside the scrollview
  • EndScrollView

hey man. i want to add a button but i cant help me please =(

cheers.

Check out http://unity3d.com/support/documentation/Components/gui-Controls.html
Or you might want to try this:

/* ScrollView example */

var scrollViewVector : Vector2 = Vector2.zero;
var innerText : String = "I am inside the ScrollView";

function OnGUI () {
    // Begin the ScrollView
    scrollViewVector = GUI.BeginScrollView (Rect (25, 25, 100, 100), scrollViewVector, Rect (0, 0, 400, 400));

// Put something inside the ScrollView
innerText = GUI.TextArea (Rect (0, 0, 400, 400), innerText);

// End the ScrollView
GUI.EndScrollView();