use bevy::prelude::*; /// This example illustrates how to use States to control transitioning from a Menu state to an InGame state. fn main() { App::build() .add_plugins(DefaultPlugins) .init_resource::() .add_state(AppState::Menu) .on_state_enter(AppState::Menu, setup_menu) .on_state_update(AppState::Menu, menu) .on_state_exit(AppState::Menu, cleanup_menu) .on_state_enter(AppState::InGame, setup_game) .on_state_update( AppState::InGame, SystemStage::parallel() .with_system(movement) .with_system(change_color), ) .run(); } #[derive(Clone)] enum AppState { Menu, InGame, } struct MenuData { button_entity: Entity, } fn setup_menu( commands: &mut Commands, asset_server: Res, button_materials: Res, ) { commands // ui camera .spawn(CameraUiBundle::default()) .spawn(ButtonBundle { style: Style { size: Size::new(Val::Px(150.0), Val::Px(65.0)), // center button margin: Rect::all(Val::Auto), // horizontally center child text justify_content: JustifyContent::Center, // vertically center child text align_items: AlignItems::Center, ..Default::default() }, material: button_materials.normal.clone(), ..Default::default() }) .with_children(|parent| { parent.spawn(TextBundle { text: Text { value: "Play".to_string(), font: asset_server.load("fonts/FiraSans-Bold.ttf"), style: TextStyle { font_size: 40.0, color: Color::rgb(0.9, 0.9, 0.9), ..Default::default() }, }, ..Default::default() }); }); commands.insert_resource(MenuData { button_entity: commands.current_entity().unwrap(), }); } fn menu( mut state: ResMut>, button_materials: Res, mut interaction_query: Query< (&Interaction, &mut Handle), (Mutated, With