bevymodsimplest_healthbar

Helps spawn and position small counter "health bars" that take a trait for max and current health, and then just shows them as text like this: "current/max" at the location of the specified camera component, make sure that the camera component specified only exists once, or this will panic

Example

``` rust use bevy::prelude::*; use bevymodsimplest_healthbar::{HealthBar, HealthBarPlugin, HealthTrait};

[derive(Component)]

struct Health { current: u32, max: u32, } impl HealthTrait for Health { fn current(&self) -> u32 { self.current }

fn max(&self) -> u32 {
    self.max
}

}

[derive(Component)]

struct BarCamera;

fn main() { App::new() .addplugins(DefaultPlugins) // custom .addplugin( // Need to define which camera we are going to be spawning the stuff in relation to, as well as what is the "health" component HealthBarPlugin::::new("fonts/FiraMono-Medium.ttf") // to automatically spawn bars on stuff with Health and a Transform .automaticbarcreation(true), ) .addstartupsystem(setup) .run(); }

fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { commands.spawn(( Camera3dBundle { transform: Transform::fromtranslation(Vec3::new(40., 40., 40.)) .lookingat(Vec3::ZERO, Vec3::Y), ..default() }, BarCamera, ));

for i in 0..5 {
    commands.spawn((
        PbrBundle {
            mesh: meshes.add(shape::Cube::default().into()),
            material: materials.add(Color::BLUE.into()),
            transform: Transform::from_translation(Vec3::new(0.0, 1.0, (i * 5) as _)),
            ..default()
        },
        Health { current: i, max: 6 },
    ));
}
commands.spawn((
    PbrBundle {
        mesh: meshes.add(shape::Cube::default().into()),
        material: materials.add(Color::BLUE.into()),
        transform: Transform::from_translation(Vec3::new(0.0, 1.0, -5.)),
        ..default()
    },
    Health { current: 4, max: 6 },
    // Create custom size and color and offset for the "bar"
    HealthBar {
        offset: Vec2::new(-4., 10.),
        size: 100.,
        color: Color::GREEN,
    },
));

} ```