The previous answers only work for smaller fonts and borders (except for Praesidium’s, that answer’s code is just not very easy to understand). This method is a little less performant than the simpler answers but will get you the border you want. It should be commented so you understand what’s going on.
void OnGUI()
{
drawScore(score);
}
}
public void drawScore(int score)
{
Rect scoreRect = new Rect(10, 10, 300, 100);
if (score > 0)
{
GUIStyle style = new GUIStyle();
int borderWidth = 15;
style.fontSize = 150;
style.fontStyle = FontStyle.Bold;
DrawTextWithOutline(scoreRect, score.ToString(), style, Color.black, Color.white, borderWidth);
}
}
void DrawTextWithOutline(Rect centerRect, string text, GUIStyle style, Color borderColor, Color innerColor, int borderWidth)
{
// assign the border color
style.normal.textColor = borderColor;
// draw an outline color copy to the left and up from original
Rect modRect = centerRect;
modRect.x -= borderWidth;
modRect.y -= borderWidth;
GUI.Label(modRect, text, style);
// stamp copies from the top left corner to the top right corner
while(modRect.x <= centerRect.x + borderWidth)
{
modRect.x++;
GUI.Label(modRect, text, style);
}
// stamp copies from the top right corner to the bottom right corner
while (modRect.y <= centerRect.y + borderWidth)
{
modRect.y++;
GUI.Label(modRect, text, style);
}
// stamp copies from the bottom right corner to the bottom left corner
while (modRect.x >= centerRect.x - borderWidth)
{
modRect.x--;
GUI.Label(modRect, text, style);
}
// stamp copies from the bottom left corner to the top left corner
while (modRect.y >= centerRect.y - borderWidth)
{
modRect.y--;
GUI.Label(modRect, text, style);
}
// draw the inner color version in the center
style.normal.textColor = innerColor;
GUI.Label(centerRect, text, style);
}

This stamping motion can be modified for better performance if you know your font widths will be wider by changing all of the increments to += someNumber, like so:
. . . . . .
// stamp copies from the top left corner to the top right corner
while(modRect.x <= centerRect.x + borderWidth)
{
modRect.x += 2;
if(modRect.x > centerRect.x + borderWidth){
modRect.x = centerRect.x + borderWidth;
}
GUI.Label(modRect, text, style);
}
. . . . . .
but smaller font widths will break this as it skips pixels.
Is the problem that the borders are too small when the font-size grows? If so, could shift by
– Owen-ReynoldsfontSize/12instead of always 1 and 2.that example generates 5 GUI elements pr. text. Thats how it was done with old HTML and CSS, but I am not sure this is the best approach in a realtime environment as Unity. You can provide your own FONTS too.
– BerggreenDK