I'm developing a game using the Bevy game engine and I want to play different sounds based on the current state of the application. I have a State
resource that keeps track of the current app state using the bevy::prelude::State
struct.
Here's my code for the play_music_system
function that should play the appropriate sound based on the current app state:
pub mod music {
use crate::state::game_state::*;
use bevy::prelude::*;
pub fn play_music_system(
audio: Res<Audio>,
game_state: Res<State<AppState>>,
asset_server: Res<AssetServer>,
) {
match game_state.current() {
AppState::MainMenu => {
let menu_music =
asset_server.load("sounds/Vitality_-_Electro_Shock_Sport_Dance.ogg");
audio.play(menu_music);
}
AppState::InGame => {}
AppState::Credits => {}
AppState::GamePaused => {}
AppState::Score => {}
}
}
}
However, I'm encountering an error no method named 'current' found for struct 'bevy::prelude::Res'<'_, bevy::prelude::State<game_state::AppState>>' in the current scope
. It seems that the current method is not available on the game_state resource like it was here. It looks like I missed a change between versions or something like that.
I would appreciate any guidance on how to correctly check the current app state and play the corresponding sound based on that state using Bevy. Thank you!