using System.Collections; using System.Collections.Generic; using UnityEngine; public class L001 : MonoBehaviour { public GameObject effectPrefab; public AudioClip sound; private GameObject[] enemies; void Start () { enemies = GameObject.FindGameObjectsWithTag("Enemy"); StartCoroutine("DestroyE"); } // コルーチン + foreach private IEnumerator DestroyE() { foreach(GameObject g in enemies) { GameObject effect = Instantiate(effectPrefab, g.transform.position, Quaternion.identity); Destroy(effect, 0.5f); AudioSource.PlayClipAtPoint(sound, Camera.main.transform.position); Destroy(g); yield return new WaitForSeconds(1.5f); } } }