I have problem with WaitForSecond

I want to fade in my scene and I want to delay it for 3 seconds but function WaitForSeconds don’t work
I read in document and write in correct structure but it still don’t work
what did i do wrong?

#pragma strict
 
var fadeTexture : Texture2D;
var fadeSpeed = 0.15;
var drawDepth = -1000;

private var alpha = 0.0; 
private var fadeDir = -1;                                      
	                                                                                                           
function OnGUI(){
   FadeIn();
}

function FadeIn()
{   yield WaitForSeconds (2);
    alpha -= fadeDir * fadeSpeed * Time.deltaTime;  
    alpha = Mathf.Clamp01(alpha);   
 
    GUI.color.a = alpha;
 
    GUI.depth = drawDepth;
 
    GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), fadeTexture);

 if(GUI.color.a == 0)
   {      
          Application.LoadLevel("Scene1");
   }
}

OnGUI is called usually more than one times per frame. You are calling each frame the FadeIn() method. So, the expected end of 2 seconds never will come.

You should use boolean flags to call the method one time. Something like this >>>

var fadeIn : booean = false;

function OnGUI ()
{
 if (fadeIn)
 {
  fadeIn = false;
  FadeIn ();
 }
}

function FadeIn ()
{
 yield WaitForSeconds (2);
    
 // and the rest of the ocde goes here
}

Haven’t checked the code, but should work.