12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace AdonGameKit
- {
- /// <summary>
- /// 延迟销毁
- /// </summary>
- 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<ParticleSystem>();
- }
- void Start()
- {
- // n秒后销毁当前gameobject
- Invoke("DestroyObject", m_Delay);
- }
- void DestroyObject()
- {
- if(m_DelayDespawn)
- {
- Delay();
- }
- else
- {
-
- Destroy(gameObject);
- }
- }
- /// <summary>
- /// 停止粒子释放并逐渐消逝
- /// </summary>
- void Delay()
- {
- if (particles.Length > 0)
- {
- for (int i = 0; i < particles.Length; i++)
- {
- particles[i].Stop(false);
- }
- }
- Destroy(gameObject,2);
- }
- }
- }
|