Time resource
This commit is contained in:
parent
2d465a926b
commit
0748cbd5d4
15
src/main.rs
15
src/main.rs
@ -6,6 +6,9 @@ struct Person;
|
||||
#[derive(Component)]
|
||||
struct Name(String);
|
||||
|
||||
#[derive(Resource)]
|
||||
struct GreetTimer(Timer);
|
||||
|
||||
fn add_people(mut commands: Commands) {
|
||||
commands.spawn((Person, Name("Lars Larson".to_string())));
|
||||
commands.spawn((Person, Name("Cedric Fagbottom".to_string())));
|
||||
@ -18,9 +21,11 @@ fn gamarjoba() {
|
||||
println!("Gamarjoba, munde!");
|
||||
}
|
||||
|
||||
fn greet_people(query: Query<&Name, With<Person>>) {
|
||||
for name in &query {
|
||||
println!("'sup {}", name.0);
|
||||
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 {
|
||||
println!("'sup {}", name.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,8 +41,10 @@ fn update_people(mut query: Query<&mut Name, With<Person>>) {
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_systems(Startup, add_people)
|
||||
.add_systems(Update, (gamarjoba, (update_people, greet_people).chain()))
|
||||
//.add_systems(Update, (gamarjoba, (update_people, greet_people).chain()))
|
||||
.add_systems(Update, (update_people, greet_people).chain())
|
||||
.run();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user