title: Unity Fade delay when game ends
body: <p>I'm fairly new at Unity and i'm trying to making a game.
  I want to have an subtitle fading in when you're at the end of the game. This start when you hit a button.
  But when I code a image that I fadein, it plays it directly when you start the game.
  Do you guys know a solution?</p>
  
  <pre><code>#pragma strict
  
  private var guiShow : boolean = false;
  
  var car : GameObject;
  var rayLength = 10;
  var guiObject : GUITexture;
  var fadeTime = 1.0;
  enum Fade {In, Out}
  var fadesubtitles : boolean = false;
  
  
  function Update ()
  {
      var hit : RaycastHit;
      var fwd = transform.TransformDirection(Vector3.forward);
  
      if(Physics.Raycast(transform.position, fwd, hit, rayLength))
      {
          if(hit.collider.gameObject.tag == "car")
          {
                  guiShow = true;
                  if(Input.GetKeyDown("e"))
                  {
                      guiShow = false;
                  }   
  
                  else if(Input.GetKeyDown("e"))
                  {
                      guiShow = false;
                  }
          }               
      }
      else
      {
      guiShow = false;
      }
  }
  
  
  
  
  function OnGUI()
  {
      if(guiShow == true)
      {
          GUI.Box(Rect(Screen.width / 2, Screen.height / 2, 150, 25), "Press F to escape");
           if(Input.GetKeyDown("f")){
                  fadesubtitles = true;
               }
       }
  }
  if (fadesubtitles == true){
               yield FadeGUITexture(guiObject, fadeTime, Fade.In);
               yield WaitForSeconds(3.0);
               yield FadeGUITexture(guiObject, fadeTime, Fade.Out);
  }
  
  function FadeGUITexture (guiObject : GUITexture, timer : float, fadeType : Fade) {
       if (subtitles == true){
       var start = fadeType == Fade.In? 0.0 : 1.0;
       var end = fadeType == Fade.In? 1.0 : 0.0;
       var i = 0.0;
       var step = 1.0/timer;
  
         while (i &lt; 1.0) {
           i += step * Time.deltaTime;
           guiObject.color.a = Mathf.Lerp(start, end, i)*.5;
           yield;
         }
       }
  }   
  </code></pre>