(Unity)敵を順番に破壊してエフェクトを出す(コルーチンの活用)

(サンプルコード)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChainBomb : MonoBehaviour
{
    private GameObject[] blocks;
    public GameObject effectPrefab;

    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            blocks = GameObject.FindGameObjectsWithTag("Block");

            // ★参考コード
            StartCoroutine(ChainEx());
        }
    }

    // ★参考コード(コルーチン)
    private IEnumerator ChainEx()
    {
        foreach (GameObject g in blocks)
        {
            Destroy(g.gameObject);
            GameObject effect = Instantiate(effectPrefab, g.transform.position, Quaternion.identity);
            Destroy(effect, 1.0f);

            yield return new WaitForSeconds(0.15f);
        }
    }
}

(実行結果)