(Unity)10回点滅後、自爆するオブジェクトの作成(コルーチンの活用)

(スクリプト)

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

public class Blinking : MonoBehaviour
{
    public GameObject effectPrefab;

    void Start()
    {
        StartCoroutine(Blink());
    }

    IEnumerator Blink()
    {
        // 10回点滅
        for(int i = 0; i < 10; i++)
        {
            this.gameObject.GetComponent<MeshRenderer>().enabled = false;
            yield return new WaitForSeconds(0.2f);
            this.gameObject.GetComponent<MeshRenderer>().enabled = true;
            yield return new WaitForSeconds(0.2f);
        }

        // 10回点滅後、爆発
        Destroy(gameObject);
        GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
        Destroy(effect, 1.0f);
    }
}

(実行結果)