title: Coroutine wait for method before going on
body: <p>I have a coroutine that downloads a video, writes it into the memory and then, plays it.</p>
  
  <pre><code>IEnumerator DownloadVideo(string url) {
      UnityWebRequest www = UnityWebRequest.Get(url);
      yield return www.SendWebRequest();
      byte[] result = www.downloadHandler.data;
      File.WriteAllBytes(path, result);
      StartCoroutine(PlayVideo(path, 3));
  }
  
  IEnumerator PlayVideo(string url, float delayTime = 0) {
      yield return new WaitForSeconds(delayTime);
      player.url = url;        
      player.Prepare();        
      while (!player.isPrepared) yield return null;
      player.Play();
  }
  </code></pre>
  
  <p>The problem is that I have to set this argument <code>delayTime</code> in the <code>PlayVideo</code> coroutine, because <code>File.WriteAllBytes(path, result)</code> takes a while to finish and if I start playing the video immediatly, it won't play correctly.</p>
  
  <p>The question is simple: in the coroutine <code>DownloadVideo</code>, how can I wait until <code>File.WriteAllBytes(path, result)</code> finish to call <code>StartCoroutine(PlayVideo(path))</code>?</p>