title: how to wait for a specific number of seconds in unity
body: <p>I want to make a loading bar in unity 2d game by instantiating 7 cubes every 1 second.
  I used :
   <code>yield WaitForSeconds(1);</code>
  in the function update after every instantiate statement but it didn't work :(( I got an error which is :</p>
  
  <blockquote>
    <p>Script error : Update() can not be a coroutine.</p>
  </blockquote>
  
  <p>Any other idea?</p>
  
  <p>I made a new scene and named it "lose" then I wrote this script and attached it to the main camera:</p>
  
  <pre><code>#pragma strict
  
  //var loadingBar: Transform;
  var loading_bar : GameObject;
  
  function Update()
  {
      Instantiate(loadingBar,Vector3(-1.849,-2.9371,2),Quaternion.identity);
  
      gameTimer();
  
  
      Instantiate(loadingBar,Vector3(-1.2909,-2.937,2),Quaternion.identity);
  
      gameTimer();
  
      Instantiate(loadingBar,Vector3(-0.5566,-2.93711,2),Quaternion.identity);
  
      gameTimer();
  
      Instantiate(loadingBar,Vector3(0.148236,-2.93711,2),Quaternion.identity);
  
      gameTimer();
  
      Instantiate(loadingBar,Vector3(0.823772,-2.93711,2),Quaternion.identity);
  
      gameTimer();
  
      Instantiate(loadingBar,Vector3(1.440567,-2.93711,2),Quaternion.identity);
  
      gameTimer();
  
      Instantiate(loadingBar,Vector3(2.057361,-2.93711,2),Quaternion.identity);
  
      loadingTimer();
  
      Application.LoadLevel(1);
  }
  
  
  function OnGUI()
  {
      GUI.color = Color.green;
      GUI.Label(Rect(400,350,500,500),"&lt;color=green&gt;&lt;size=100&gt;Lose&lt;/size&gt;&lt;/color&gt;");
  }
  
  function loadingTimer()
  {
      yield WaitForSeconds(1);
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/uix47.png" alt="enter image description here"></p>
  
  <blockquote>
    <p><strong>I want to these cubes to appear after each other by 1 second so it
    will seem like a loading bar ...</strong></p>
  </blockquote>
  
  <p><strong><em>I solved this problem by this way ::</em></strong></p>
  
  <pre><code>#pragma strict
  
  var loadingBar: Transform;
  var finished : boolean = false;
  
  function Update()
  {
      loadingTimer();
  
      if (finished == true)
      {
          Application.LoadLevel(1);
          finished= false;
      }
  }
  
  
  function OnGUI()
  {
      GUI.color = Color.green;
      GUI.Label(Rect(295,320,500,500),"&lt;color=green&gt;&lt;size=100&gt;Lose&lt;/size&gt;&lt;/color&gt;");
  
  }
  
  
  function loadingTimer()
  {
      Instantiate(loadingBar,Vector3(-1.9,-2.9371,2),Quaternion.identity);
      yield WaitForSeconds(0.28);
      Instantiate(loadingBar,Vector3(-1.3,-2.937,2),Quaternion.identity);
      yield WaitForSeconds(0.28);
      Instantiate(loadingBar,Vector3(-1.3,-2.937,2),Quaternion.identity);
      yield WaitForSeconds(0.28);
      Instantiate(loadingBar,Vector3(-0.7,-2.93711,2),Quaternion.identity);
      yield WaitForSeconds(0.28);
      Instantiate(loadingBar,Vector3(-0.1,-2.93711,2),Quaternion.identity);
      yield WaitForSeconds(0.28);
      Instantiate(loadingBar,Vector3(0.5,-2.93711,2),Quaternion.identity);
      yield WaitForSeconds(0.28);
      Instantiate(loadingBar,Vector3(1.1,-2.93711,2),Quaternion.identity);
      yield WaitForSeconds(0.28);
      Instantiate(loadingBar,Vector3(1.7,-2.93711,2),Quaternion.identity);
  
      finished= true;
  }
  </code></pre>