using System.Collections; using UnityEngine; // Play On Awakeで再生するワンショットエフェクトの親に追加します。 [DisallowMultipleComponent] public sealed class DestroyAfterParticles : MonoBehaviour { private ParticleSystem[] particleSystems; private IEnumerator Start() { particleSystems = GetComponentsInChildren(true); // 子の自動再生が開始するフレームを待ちます。 yield return null; while (HasAliveParticles()) { yield return null; } Destroy(gameObject); } private bool HasAliveParticles() { foreach (ParticleSystem particles in particleSystems) { if (particles != null && particles.gameObject.activeInHierarchy && particles.IsAlive(false)) { return true; } } return false; } }