QUIText Fade In?

I use this code for QUIText to fade out:

 #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;
     }
 }

How do i make it fade in instead of out?

Thanks For Help!

You are on the right track richyrich but remember that color values are between 0 and 1 in scripting (not 0 - 255 as in a color picker).

captainkrisu the Fade() function in the script above is being called every frame by Update(), so having a while loop seems very odd. You would use a loop if this was a coroutine that was activated once with the yield having an associated time value to slow the Fade process down.

Something like this will work(this will fade in and out repeatedly) :

#pragma strict

public var MyGUIText : GUIText;
private var fFade_In_Speed : float;

function Start() {

    fFade_In_Speed = 0.2;
    
    InvokeRepeating("Fade", 0, fFade_In_Speed);
}

function Fade() {

    if (MyGUIText.material.color.a >= 0) {
        MyGUIText.material.color.a -= 0.05;
        
    } else {
        MyGUIText.material.color.a = 0.0;
        CancelInvoke("Fade");
        InvokeRepeating("Fade_In", 0, fFade_In_Speed);
    }
}

function Fade_In() {

    if (MyGUIText.material.color.a <= 1) {
        MyGUIText.material.color.a += 0.05;
        
    } else {
        MyGUIText.material.color.a = 1.0;
        CancelInvoke("Fade_In");
        InvokeRepeating("Fade", 0, fFade_In_Speed);
    }
}

Place this on the GUIText object. Then drag the GUIText object from the hierarchy window into the MyGUIText var box.