Fading GUI text

Ive been looking around and from different posts I’ve put together a script that has a GUI text in the middle of the screen for certain amount of time. However it doesn’t seem to work properly. The GUI text is there but its very small and its not in one line, also it fails to fade away. could someone find where I’ve gone wrong. Thanks
var color : Color;

function Start()
{
    color = Color.white;
    yield FadeOutAfterTime(5);
}
 
function OnGUI () {
    var centeredStyle = GUI.skin.GetStyle("Label");
    centeredStyle.alignment = TextAnchor.UpperCenter;
    GUI.Label (Rect (Screen.width/2-50, Screen.height/2-25, 100, 50), "Level 1", centeredStyle);
}
 
function FadeOutAfterTime(time : float)
{
    yield WaitForSeconds(5);
    yield Fade();
}
 
function Fade()
{
   while (color.a > 0)
   { 
       color.a -= Time.deltaTime;
       yield;
   }
}

Add a GUI Text to your scene, make a new script, put this in -

#pragma strict

var color : Color;

function Start(){
    
    color = Color.white;
}

function Update(){

	Fade();
}
 
function Fade(){

	while (guiText.material.color.a > 0){
		guiText.material.color.a -= 0.1 * Time.deltaTime * 0.05;
	yield;
	}
}

In the inspector set to what you want, like below, using another font like I have to get a better and bigger effect -

9032-grab-01.jpg

Update this answer to unity 5:

Since color is a struct, the line:

material.color.a -= 0.1 * Time.deltaTime * 2;

will be a compiler error.

The right way to do it would be saving the color to a local variable, or better using Color.operator-

material.color -= new Color(0, 0, 0, 0.1 * Time.deltaTime * 2);

But the best way in my opinion is using Color.Lerp

public float FadeoutTime;
private Color startColor;
private Color endColor;

void Start()
{
    startColor = GetComponent<Text>().color;
    endColor = startColor - new Color(0, 0, 0, 1.0f);
}
	
void Update () 
{
	GetComponent<Text>().color = Color.Lerp(startColor, endColor, FadeoutTime)
}