// Counts changes into a game resource: `ResMut<T>` and `Changed` / `Added`.
fn touch(mut q: Query<&mut Health, With<Regen>>) {
for mut hp in &mut q {
hp.0 += 1.0;
}
}
fn count_changed(mut score: ResMut<Score>, q: Query<&Health, Changed<Health>>) {
for _hp in &q {
score.changed += 1;
}
}
fn count_added(mut score: ResMut<Score>, q: Query<&Health, Added<Health>>) {
for _hp in &q {
score.added += 1;
}
}
fn read_only(score: Res<Score>, mut q: Query<&mut Regen>) {
for mut r in &mut q {
r.per_sec = score.added as f32;
}
}
pub fn plugin(app: &mut App) {
app.add_systems(Update, (touch, count_changed, count_added, read_only));
}