0
1

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 1 year has passed since last update.

コルーチンとは

Posted at

フレームをまたいで処理を実行したいときに使用する。
→「〇〇するまで待つ」を再現したいときに便利。

たとえば、
・5秒かけて画像をフェードインする
→5秒経過するまで待つ

・Enterキーが押されたら次のゲームステータスに移行する
→Enterキーが押されるまで待つ

〇Unityにおける使用例

private float seconds = 0.0f;

void Start()
{
    StartCoroutine(TimeCount());//コルーチンの開始
}

private IEnumerator TimeCount()//コルーチンで行う処理の定義
{
    while (true)//無限ループ
    {
        yield return new WaitForSeconds(5.0f);//5秒経過するまで待つ
        seconds += 5.0f;
        Debug.Log(seconds + "秒経過");
    }
}

出力
image.png

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?