title: Getting return value of a Coroutine in unity
body: <p>I'm trying to insert a user to external database in unity. 
  I need to wait until web server replies with a error or success, but I'm unable to do it....</p>
  
  <p>Here is what I have done until now:</p>
  
  <pre><code>public class DBConnector : MonoBehaviour
  {
      string BASE_URL = "https://www.XXXXXX.com/API/";
  
      public DBConnector()
      {
      }
  
      public int registerUser(User user)
      {
          int returnInt = -1;
  
          StartCoroutine(RegisterUser(user, returnValue =&gt;
          {
              returnInt = returnValue;
          }
          ));
  
          Debug.Log(returnInt);
          return returnInt;
      }
  
      IEnumerator RegisterUser(User user, System.Action&lt;int&gt; callback = null)
      {
          Debug.Log("a register user");
  
          WWWForm form = new WWWForm();
  
          using (UnityWebRequest www = UnityWebRequest.Post(BASE_URL + "userAPI.php", form))
          {
              yield return www.SendWebRequest();
  
              if (www.isNetworkError || www.isHttpError)
              {
                  Debug.Log(www.error);
                  yield return 1;
              }
              else
              {
                  Debug.Log(www.downloadHandler.text);
  
                  yield return 0;
              }
          }
      }
  }
  </code></pre>
  
  <p>and calling it :</p>
  
  <pre><code>        Debug.Log("Before registerUser");
  
          conn = FindObjectOfType&lt;DBConnector&gt;();
          result = conn.registerUser(user);
  
          Debug.Log("After registerUser");
  
          if (result == 0)
          {
              SceneManager.LoadScene("AccountCreatedScene");
          }
  </code></pre>
  
  <p>the RegisterUser callback is finished after the registerUser method is finish so always returns -1.</p>
  
  <p>I'm quite newbie on networking thing, so please help.....How to do it?</p>
  
  <p>Thanks</p>