Added finish method for timer (#20154)

# Objective

- Add an easy way to finish a Timer

## Solution

- Tick the timer by the remaining time

## Testing

I have not tested, but it should work
---

## Showcase

```rust
let mut timer = Timer::from_seconds(1.5, TimerMode::Once);
timer.finish();
assert_eq!(timer.remaining(), Duration::from_secs(0))
```

---------

Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
Lenchog 2025-07-16 08:57:57 +10:00 committed by GitHub
parent d195116426
commit 8e14d99fb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -220,6 +220,21 @@ impl Timer {
self.duration = duration;
}
/// Finishes the timer.
///
/// # Examples
/// ```
/// # use bevy_time::*;
/// let mut timer = Timer::from_seconds(1.5, TimerMode::Once);
/// timer.finish();
/// assert!(timer.finished());
/// ```
#[inline]
pub fn finish(&mut self) {
let remaining = self.remaining();
self.tick(remaining);
}
/// Returns the mode of the timer.
///
/// # Examples