riversong code showcase
This commit is contained in:
40
Source/Riversong/Game/Vfx/AutoDestroyVfx.cs
Normal file
40
Source/Riversong/Game/Vfx/AutoDestroyVfx.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user