//! Illustrates how `Timer`s can be used both as resources and components. use bevy::{log::info, prelude::*}; fn main() { App::new() .add_plugins(DefaultPlugins) .init_resource::() .add_systems(Startup, setup) .add_systems(Update, (countdown, print_when_completed)) .run(); } #[derive(Component, Deref, DerefMut)] struct PrintOnCompletionTimer(Timer); #[derive(Resource)] struct Countdown { percent_trigger: Timer, main_timer: Timer, } impl Countdown { pub fn new() -> Self { Self { percent_trigger: Timer::from_seconds(4.0, TimerMode::Repeating), main_timer: Timer::from_seconds(20.0, TimerMode::Once), } } } impl Default for Countdown { fn default() -> Self { Self::new() } } fn setup(mut commands: Commands) { // Add an entity to the world with a timer commands.spawn(PrintOnCompletionTimer(Timer::from_seconds( 5.0, TimerMode::Once, ))); } /// This system ticks the `Timer` on the entity with the `PrintOnCompletionTimer` /// component using bevy's `Time` resource to get the delta between each update. fn print_when_completed(time: Res