public float time = 0f;
void Start()
{
time = ParticleSystemLength();
Invoke("DestroySelf", time);
print(ParticleSystemLength());
}
void DestroySelf()
{
Destroy(this.gameObject);
}
float ParticleSystemLength()
{
ParticleSystem []particleSystems = this.transform.GetComponentsInChildren<ParticleSystem>();
float maxDuration = 0;
foreach(ParticleSystem ps in particleSystems){
if(ps.enableEmission){
if(ps.loop){
return -1f;
}
float dunration = 0f;
if(ps.emissionRate <=0){
dunration = ps.startDelay + ps.startLifetime;
}else{
dunration = ps.startDelay + Mathf.Max(ps.duration,ps.startLifetime);
}
if (dunration > maxDuration) {
maxDuration = dunration;
}
}
}
return maxDuration;
}
unity自动获取特效的播放时间,并自动删除特效
最新推荐文章于 2025-03-05 15:44:08 发布