4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

unityWebRequestが返ってくるまで、システム全体を停止させるコルーチン

Last updated at Posted at 2016-10-01

タイトルの通りです。JokerScriptなどのラノベゲームなどで、リクエストを行う際に使いました。

    public IEnumerator GetTexture()
    {
        UnityWebRequest www = UnityWebRequest.Get("https://localhost:8000");
        
        AsyncOperation checkAsync = www.Send();
        
        while (!checkAsync.isDone);

        if (www.isError)
        {
            Debug.Log(www.error);
        }
        else
        {
            Debug.Log(www.downloadHandler.text);
        }

        yield return null;
    }

結果

うまく動作しました後日再度確認してみるとうまく動作をしませんでした。現在調査中です。

参考コード

再度挑戦!!

どうやらコルーチンの呼び出し方法はStartCoroutine()だけじゃないようです。
以下のようにMoveNext()を使って上のGetTexture()を呼び出したらうまくいきました!


    public void GetRequest()
    {
        IEnumerator coroutine = GetTexture();
        coroutine.MoveNext();
    }

参考

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?