0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Unityのasync/awaitの使い方

Posted at

Async/awaitとは...

Asyncは非同期処理であることを定義する時に使う

awaitは指定した処理が完了するまで非同期で待つ。

非同期処理とはキャラクターを動かす処理などのメインとなる部分とは同期をせずに行う処理のことである。

例をあげると、ゲームのローディング中に遊べるミニゲームなどがある。

使用例

        Debug.Log("1");
        
        await OneSecond();
        
        Debug.Log("2");

        async Task OneSecond()//asyncで非同期処理を定義
        {
            await Task.Delay(1000);//1s待機
        }

Taskは非同期処理が完了した場合に通知を送ってくれるようなイメージ。そのためawaitの処理を使う上で同時に覚えておく必要がある

まとめ

・asyncは非同期処理をさせたいときに使う

・awaitは処理が完了するまで非同期で待機

・Taskは処理の完了を教えてくれる

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?