I have a camera entity that I want to change its behavior based on the current app state (e.g., in-game, main menu, splash screen). I've tried to use the app state in a Bevy system to modify the camera's properties, but I'm encountering a trait-bound error that I can't quite resolve.
Here's a simplified version of my code:
#[derive(Resource)]
pub struct Camera(Entity);
fn spawn_camera(mut commands: Commands) {
let camera = commands.spawn(Camera2dBundle::default()).id();
commands.insert_resource(Camera(camera));
}
fn camera_system(camera: Res<Camera>, app_state: State<AppState>) {
match app_state.get() {
AppState::Gaming => {
println!("{:?}", camera.0);
}
_ => {}
}
}
pub struct CameraSystem;
impl Plugin for CameraSystem {
fn build(&self, app: &mut App) {
app.add_systems(Startup, spawn_camera);
app.add_systems(Update, camera_system);
}
}