game states cleanup
This commit is contained in:
+14
-4
@@ -46,16 +46,26 @@ fn update_depth_text(
|
||||
}
|
||||
}
|
||||
|
||||
fn cleanup_score(mut commands: Commands, entities: Query<Entity, With<DepthText>>) {
|
||||
for entity in entities {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ScorePlugin;
|
||||
|
||||
impl Plugin for ScorePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_depth_text)
|
||||
.init_resource::<Depth>()
|
||||
app.init_resource::<Depth>()
|
||||
.add_systems(OnEnter(GameState::InGame), spawn_depth_text)
|
||||
.add_systems(
|
||||
Update,
|
||||
(update_depth_text, update_depth.after(move_player))
|
||||
(
|
||||
update_depth_text.after(spawn_depth_text),
|
||||
update_depth.after(move_player),
|
||||
)
|
||||
.run_if(in_state(GameState::InGame)),
|
||||
);
|
||||
)
|
||||
.add_systems(OnExit(GameState::InGame), cleanup_score);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user