resources

main
Zynh Ludwig 2024-07-29 23:08:56 -07:00
parent 19f4c5280e
commit 0db4cf5fce
1 changed files with 11 additions and 5 deletions

View File

@ -20,17 +20,23 @@ fn add_people(mut commands: Commands) {
commands.spawn((Person, Name("Zayna Nieves".to_string()))); commands.spawn((Person, Name("Zayna Nieves".to_string())));
} }
fn greet_people(query: Query<&Name, With<Person>>) { #[derive(Resource)]
struct GreetTimer(Timer);
fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
if timer.0.tick(time.delta()).just_finished() {
for name in &query { for name in &query {
println!("hello {}!", name.0); println!("hello {}!", name.0);
} }
}
} }
pub struct HelloPlugin; pub struct HelloPlugin;
impl Plugin for HelloPlugin { impl Plugin for HelloPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(Startup, add_people) app.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
.add_systems(Update, (hello_world, greet_people).chain()); .add_systems(Startup, add_people)
.add_systems(Update, greet_people);
} }
} }