diff --git a/crates/bevy_ecs/src/schedule/state.rs b/crates/bevy_ecs/src/schedule/state.rs index 82a616710e..dacb5605ec 100644 --- a/crates/bevy_ecs/src/schedule/state.rs +++ b/crates/bevy_ecs/src/schedule/state.rs @@ -74,6 +74,27 @@ pub struct OnTransition { /// [`apply_state_transition::`] system. /// /// The starting state is defined via the [`Default`] implementation for `S`. +/// +/// ``` +/// use bevy_ecs::prelude::*; +/// +/// #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default, States)] +/// enum GameState { +/// #[default] +/// MainMenu, +/// SettingsMenu, +/// InGame, +/// } +/// +/// fn game_logic(game_state: Res>) { +/// match game_state.get() { +/// GameState::InGame => { +/// // Run game logic here... +/// }, +/// _ => {}, +/// } +/// } +/// ``` #[derive(Resource, Debug)] #[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] pub struct State(S); @@ -117,6 +138,22 @@ impl Deref for State { /// To queue a transition, just set the contained value to `Some(next_state)`. /// Note that these transitions can be overridden by other systems: /// only the actual value of this resource at the time of [`apply_state_transition`] matters. +/// +/// ``` +/// use bevy_ecs::prelude::*; +/// +/// #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default, States)] +/// enum GameState { +/// #[default] +/// MainMenu, +/// SettingsMenu, +/// InGame, +/// } +/// +/// fn start_game(mut next_game_state: ResMut>) { +/// next_game_state.set(GameState::InGame); +/// } +/// ``` #[derive(Resource, Debug)] #[cfg_attr( feature = "bevy_reflect",