40 lines
890 B
C#
40 lines
890 B
C#
using UnityEngine;
|
|
using UnityEngine.VFX;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
[RequireComponent(typeof(VisualEffect))]
|
|
public class AutoDestroyVfx : MonoBehaviour
|
|
{
|
|
private const float DestroyDelayWhenNoParticles = 1;
|
|
|
|
private VisualEffect _vfx;
|
|
|
|
private bool _emittedOnce;
|
|
|
|
private float _timer;
|
|
|
|
private void Awake()
|
|
{
|
|
_vfx = GetComponent<VisualEffect>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!_vfx) return;
|
|
|
|
_emittedOnce |= _vfx.aliveParticleCount > 0;
|
|
if (!_emittedOnce) return;
|
|
|
|
if (_vfx.aliveParticleCount > 0)
|
|
{
|
|
_timer = 0;
|
|
return;
|
|
}
|
|
|
|
_timer += Time.unscaledDeltaTime;
|
|
|
|
if (_timer >= DestroyDelayWhenNoParticles) Destroy(gameObject);
|
|
}
|
|
}
|
|
} |