LoginSignup
0
0

More than 3 years have passed since last update.

StartCoroutine での切り替わりのタイミング

Posted at

環境

Unity2017.4.1f1

コルーチン呼び出しで、関数が切り替わるタイミングのメモ。

    void Start () {
        int twork = 0;
        Debug.Log("Start1 twork="+twork);
        StartCoroutine( Test00( (T) => { twork = T; } ) );
        Debug.Log("Start2 twork="+twork);
    }

    public IEnumerator Test00(Action<int> func)
    {
        func(99);
        yield return null;
        func(88);
        Debug.Log("Start3 ");
    }

上記のようなコードを作成して実行してみた。
なんとなく、コルーチン処理は登録後、即座に実行はされていないと思っていた。
つまり、
Start2 twork=0
となるのではないか?

結果

Start1 twork=0
Start2 twork=99
Start3

となった。
なるほど、StartCoroutineが呼ばれた後は、その関数に遷移し、yield return が呼ばれるまで処理を行い
呼ばれた後に呼び先の関数の処理が継続されるのね。

個人的な備忘録です。

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