41 lines
995 B
C#
41 lines
995 B
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using Invector;
|
|
using Lean.Pool;
|
|
|
|
namespace Beyond
|
|
{
|
|
[vClassHeader("Destroy GameObject", openClose = false)]
|
|
public class DespawnGameObject : vMonoBehaviour
|
|
{
|
|
public float delay = 1f;
|
|
public UnityEngine.Events.UnityEvent onDestroy;
|
|
public bool m_returnToPool = true;
|
|
|
|
private float timeOffset = 1f;
|
|
|
|
IEnumerator DestroyDelay()
|
|
{
|
|
yield return new WaitForSeconds(delay + timeOffset);
|
|
|
|
AudioSource audio = GetComponent<AudioSource>();
|
|
if (audio != null)
|
|
{
|
|
yield return new WaitUntil(() => !audio.isPlaying);
|
|
}
|
|
|
|
onDestroy?.Invoke();
|
|
if (m_returnToPool)
|
|
LeanPool.Despawn(gameObject);
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
StartCoroutine(DestroyDelay());
|
|
}
|
|
}
|
|
} |