using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace AdonGameKit
{
///
/// 延迟销毁
///
public class DestroyObjectDelayed : MonoBehaviour
{
public float m_Delay = 5;
public bool m_DelayDespawn;///粒子延迟淡出再销毁
// Start is called before the first frame update
ParticleSystem[] particles;//粒子系统数组
void Awake()
{
particles = GetComponentsInChildren();
}
void Start()
{
// n秒后销毁当前gameobject
Invoke("DestroyObject", m_Delay);
}
void DestroyObject()
{
if(m_DelayDespawn)
{
Delay();
}
else
{
Destroy(gameObject);
}
}
///
/// 停止粒子释放并逐渐消逝
///
void Delay()
{
if (particles.Length > 0)
{
for (int i = 0; i < particles.Length; i++)
{
particles[i].Stop(false);
}
}
Destroy(gameObject,2);
}
}
}