Unity3D粒子系统——实现粒子播放完成之后自动销毁

在带有粒子系统的根对象中加入组件ParticleAutoDestruction.cs即可,其中ParticleAutoDestruction组件代码如下:

using UnityEngine;
using System.Collections;

public class ParticleAutoDestruction : MonoBehaviour
{
    private ParticleSystem[] particleSystems;

    void Start()
    {
        particleSystems = GetComponentsInChildren();
    }
	
	void Update ()
    {
        bool allStopped = true;

        foreach (ParticleSystem ps in particleSystems)
        {
            if (!ps.isStopped)
            {
                allStopped = false;
            }
        }

        if (allStopped)
            GameObject.Destroy(gameObject);
	}
}


你可能感兴趣的:(常用Unity小功能)