LoginSignup
1
1

More than 5 years have passed since last update.

Unityでラムダ式を遅延実行する

Last updated at Posted at 2014-12-30

    public void DelayFunc(int frame, Action action){
        StartCoroutine(_DelayFunc(frame, action));
    }

    private IEnumerator _DelayFunc(int frame, Action act){
        for (int i = 0; i < frame; ++i) yield return null;
        action();
    }

使い道があるような、ないような。

あんまり良い使い道が思いつきませんが、

        for (int i = 0; i < 10;++i){
            int cnt = i;
            DelayFunc(i * 30, () => Debug.Log(cnt * 30 + "フレーム後の時間:" + Time.time));
        }

なんてやれば、0~300フレームまでの30フレーム刻みの時間が表示されたりします。
ちなみに、無駄そうに見える

int cnt = i;

は無駄じゃありませんのであしからず。

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