Unity-yield之后的行未执行

时间:2018-10-04 03:47:33

标签: c# unity3d

此代码在IEnumerator中:

 WWW post = new WWW(post_url);
 yield return post; 
 Debug.Log("Id: " + post.text); //This line does not get executed

任何知道为什么yield之后的语句永远都不会执行吗?

我也尝试过yield return new WaitWhile(() => hs_post.isDone==true),但前面的行仍然没有执行

编辑:按评论要求,下面是完整的代码:

//Called on button click
public void ShowLB(){
    PlayerPrefs.SetString ("Username", input.text);
    Debug.Log ("Showing leaderboard");
    StartCoroutine (InitRow ());
    this.gameObject.SetActive (false);
}

private IEnumerator InitRow(){
    string secretKey = "youDontNeedToKnow";
    string name = PlayerPrefs.GetString ("Username");
    string addScoreURL = ("https://mywebsite.com/insert.php?");
    string hash = Md5Sum(name + 0 + secretKey);
    string post_url = addScoreURL + "name=" + WWW.EscapeURL(name) + "&score=" + 0 + "&hash=" + hash;
    WWW hs_post = new WWW(post_url);
    yield return hs_post;

    if (hs_post.error != null) {
        Debug.Log ("There was an error posting the high score: " + hs_post.error);
    } else {
        Debug.Log ("No error");
    }
    Debug.Log("Id: " + hs_post.text);

    yield return null;
}

0 个答案:

没有答案