Point queries #3169
-
I'm trying to do a point query in one of my systems, by which I mean looking up Here's my code so far: pub type Hp = i32;
pub struct HealthComponent {
pub current: Hp,
pub max: Hp,
}
pub struct Player;
pub struct DamageEvent {
pub target: Entity,
pub hp: Hp,
}
fn setup(
mut commands: Commands,
) {
commands
.spawn()
.insert(Player)
.insert(HealthComponent {
current: 10,
max: 10,
}
}
fn apply_damage(
mut commands: Commands,
dmg_reader: mut EventReader<DamageEvent>,
) {
for damage in dmg_reader.iter() {
let entity = commands.entity(damage.target);
let mut health: HealthComponent = todo!();
health.current -= damage.hp;
}
} The bit I'm uncertain of is what to replace the If I had access to a
I could inject a Perhaps there is a more idiomatic way to represent Any help is appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can use query.get or query.get_component :) |
Beta Was this translation helpful? Give feedback.
You can use query.get or query.get_component :)