Confusion GUI Buttom Matrix Problem

I am trying to make a 5x3 Table for the users inventory,
but for some reason it fails misably and I don’t know why.

The boxes on the screen end up like this.

The debug texts shown by “// *” prints as it should (10,100,190,etc)

    GUI.BeginGroup(Rect(10,200,Screen.width-10,500));
    //Add GUI Items Here
    var x:int;
    var curx:int;
    var y:int;
    var cury:int=10;
    var a:int=0;
    for (y=0;y<1;y++){ //Just do 1 row until i fix it: 3 normally
        curx=10;
        for (x=0;x<5;x++){
        	if (a>14){
        	    Debug.Log("Oh God...");
        	}
                Debug.Log("Id:"+a+" curx:"+curx+" cury:"+cury); // *
        	if (items[a]){
        		GUI.Button(new Rect(curx,cury,curx+80,cury+80),items[a].icon);
        	}else{
        		GUI.Button(new Rect(curx,cury,curx+80,cury+80), a.ToString());
        	}
            Debug.Log("X-Id:"+a+" curx:"+(curx+80)+" cury:"+(cury+80)); // *
        		curx=curx+90;
        		a++;				
        }
        cury+=90;
      }
      GUI.EndGroup();

The button takes a rect which defines width and height, not rightmost, bottommost positions.

 GUI.Button(new Rect(curx, cury, 80, 80), items[a].icon);

The 3rd and 4th parameters in Rect are the width and the height, not the right and bottom coordinates. You should write:

     GUI.Button(new Rect(curx,cury,80,80),...);

This would create a 80x80 button with left-upper corner at curx,cury. But depending on what you’re trying to do, GUI.SelectionGrid can be a better solution - only one of the buttons remain selected at each time, and the buttons are arranged in a matrix.