GUILayout and aligned columns

I’m having a hell of a time trying to get things to left or right align properly into three separate columns using GUILayout. I have a top 10 score leaderboard in which I have three columns. It’s driven by code such as the following.

// GUI Routine to display high score list

function OnGUI () {

if (displayHighScores == true) {

// Display heading

GUILayout.BeginArea (Rect (Screen.width * 0.5 - 70,Screen.height * 0.5 - 100,150,500));
GUILayout.BeginVertical("box", GUILayout.Height(175)); 
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
GUILayout.Label("Leaderboard", HUDCenterStyle);
GUILayout.EndHorizontal();
GUILayout.Space (10);

// Iterate backwards, inverting the array sort and display columns.

var x = 10;
var y = 1;

while (x > 0) {
    GUILayout.BeginHorizontal();
    GUILayout.Label ((y).ToString(), HUDLeftStyle);
    GUILayout.Label (nameArray[x],HUDLeftStyle);
    GUILayout.Label (scoreArray[x].ToString(), HUDRightStyle);
    GUILayout.EndHorizontal();
    x -= 1;
    y += 1;
}

GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.EndArea();

}

}

As you can see in the above picture, I can’t seem to get the player names to left align properly. I’ve tried every variation of left, center, right, adding spaces in, not using flexible space, you name it…

Any advice would be appreciated.

Solved: Used GUILayout.Width() to hardcode individual column sizes.

For stuff like this, it is often easier to just use GUI. stuff and do the layouting yourself :slight_smile: