(スクリプト)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyAllEnemy : MonoBehaviour
{
private GameObject[] targets;
public GameObject effectPrefab;
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
StartCoroutine(DestroyE());
}
}
private IEnumerator DestroyE()
{
targets = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject e in targets)
{
Destroy(e);
GameObject effect = Instantiate(effectPrefab, e.transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
yield return new WaitForSeconds(0.2f);
}
}
}
(実行結果)