Files

25 lines
511 B
C#

namespace AlienAttack.MonoGame.Audio;
public sealed class RateLimiter(float cooldownSeconds)
{
private readonly float _cooldownSeconds = cooldownSeconds <= 0 ? 0.0001f : cooldownSeconds;
private float _timer = 0f;
public void Update(float deltaTime)
{
_timer -= deltaTime;
if (_timer < 0f)
_timer = 0f;
}
public bool TryConsume()
{
if (_timer > 0f)
return false;
_timer = _cooldownSeconds;
return true;
}
}