在带有粒子系统的根对象中加入组件ParticleAutoDestruction.cs即可,其中ParticleAutoDestruction组件代码如下:
using UnityEngine;
using System.Collections;
public class ParticleAutoDestruction : MonoBehaviour
{
private ParticleSystem[] particleSystems;
void Start()
{
particleSystems = GetComponentsInChildren<ParticleSystem>();
}
void Update ()
{
bool allStopped = true;
foreach (ParticleSystem ps in particleSystems)
{
if (!ps.isStopped)
{
allStopped = false;
}
}
if (allStopped)
GameObject.Destroy(gameObject);
}
}