Rust Bevy Query Option

[Solved] Rust Bevy Query Option | Rust - Code Explorer | yomemimo.com
Question : rust bevy query option

Answered by : zwazel

fn check_zero_health( // access entities that have `Health` and `Transform` components // get read-only access to `Health` and mutable access to `Transform` // optional component: get access to `Player` if it exists mut query: Query<(&Health, &mut Transform, Option<&Player>)>,
) { // get all matching entities for (health, mut transform, player) in query.iter_mut() { eprintln!("Entity at {} has {} HP.", transform.translation, health.hp); // center if hp is zero if health.hp <= 0.0 { transform.translation = Vec3::ZERO; } if let Some(player) = player { // the current entity is the player! // do something special! } }
}

Source : https://bevy-cheatbook.github.io/programming/queries.html | Last Update : Fri, 15 Apr 22

Answers related to rust bevy query option

Code Explorer Popular Question For Rust