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:
parent
d195116426
commit
8e14d99fb9
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user