Answers for "rust bevy states"

0

rust bevy states

#[derive(Clone)]
enum AppState {
    Loading,
    Menu,
    InGame
}
app.add_resource(State::new(AppState::Loading));
app.add_stage_after(stage::UPDATE, "my_stage", StateStage::<AppState>::default());

// Bind systems to run when state changes or is running
app.on_state_enter("my_stage", AppState::Menu, some_system.system());
app.on_state_update("my_stage", AppState::Menu, some_system.system());
app.on_state_exit("my_stage", AppState::Menu, some_system.system());

// Changing state
fn some_system(mut state: ResMut<State<AppState>>) {
    state.set_next(AppState::InGame).unwrap();
}
Posted by: Guest on January-26-2021

Browse Popular Code Answers by Language