//! 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_startup_system(setup) .add_system(countdown) .add_system(print_when_completed) .run(); } #[derive(Component, Deref, DerefMut)] pub struct PrintOnCompletionTimer(Timer); #[derive(Resource)] pub struct Countdown { pub percent_trigger: Timer, pub 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 all the `Timer` components on entities within the scene /// using bevy's `Time` resource to get the delta between each update. fn print_when_completed(time: Res