No timer to tick. No Time.Delta to track.

The usual way
A timer you tick yourself.
float _cooldown; protected override void OnUpdate(){ _cooldown -= Time.Delta; bool fire = Input.Pressed( "attack1" ); if ( fire && _cooldown <= 0f ) { Shoot(); _cooldown = 0.5f; }}
It works, as long as you remember to tick the timer every single frame.
The fix
A timer that counts itself.
TimeUntil is an s&box type. Set it to a number of seconds and it counts down on its own.
_nextShot = 0.5f→ready in 0.5s
The fix in code
Set it and forget it.
TimeUntil _nextShot; protected override void OnUpdate(){ bool fire = Input.Pressed( "attack1" ); if ( fire && _nextShot <= 0f ) { Shoot(); _nextShot = 0.5f; }}
No ticking. _nextShot reaches zero the moment half a second has passed.
Its twin
TimeSince counts up.
TimeSince _sinceHit; void OnHit() => _sinceHit = 0; bool Invulnerable => _sinceHit < 1f;
Set it to 0 to start. It reads as the seconds since then.
The rule
Let the timer keep the time.
- Count down
- TimeUntil
- Count up
- TimeSince
- Manual ticking
- not needed