在带有粒子系统的根对象中加入组件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);
}
}
本文介绍了一个Unity脚本ParticleAutoDestruction,该脚本用于在游戏中当所有粒子效果停止播放时自动销毁粒子系统及其所在的对象。
1479

被折叠的 条评论
为什么被折叠?



