Time
The time resource can be used to track the global runtime of our App. Bevy also
includes a Timer type which makes it easy to track how much time has passed
during a series of events:
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
.add_systems(Update, greet_people)
.run();
}
#[derive(Resource)]
struct GreetTimer(Timer);
fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>) {
if timer.0.tick(time.delta()).just_finished() {
println!("beep");
}
}