Support Warning
WebGPU is currently only supported on Chrome starting with version 113, and only on desktop. If they don't work on
your configuration, you can check the WebGL2 examples
here.
use bevy::{prelude::*, utils::Duration};
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
PrintMessagePlugin {
wait_duration: Duration::from_secs(1),
message: "This is an example plugin".to_string(),
},
))
.run();
}
struct PrintMessagePlugin {
wait_duration: Duration,
message: String,
}
impl Plugin for PrintMessagePlugin {
fn build(&self, app: &mut App) {
let state = PrintMessageState {
message: self.message.clone(),
timer: Timer::new(self.wait_duration, TimerMode::Repeating),
};
app.insert_resource(state)
.add_systems(Update, print_message_system);
}
}
#[derive(Resource)]
struct PrintMessageState {
message: String,
timer: Timer,
}
fn print_message_system(mut state: ResMut<PrintMessageState>, time: Res<Time>) {
if state.timer.tick(time.delta()).finished() {
info!("{}", state.message);
}
}