use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; use bevy_variable_property::{interval_property::*, prelude::*}; #[derive(Component)] pub struct MyIntervalProperty(pub IntervalProperty>); impl AsMut>> for MyIntervalProperty { fn as_mut(&mut self) -> &mut IntervalProperty> { &mut self.0 } } impl IntervalPropertyComponent for MyIntervalProperty { type Property = Property; type TargetComponent = Transform; fn update(new_value: &Vec2, target: &mut Transform) { target.translation = new_value.extend(target.translation.z); } } fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .add_systems(Update, MyIntervalProperty::system) .run(); } fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { commands.spawn(Camera2dBundle::default()); commands.spawn(( MaterialMesh2dBundle { mesh: meshes .add(Mesh::from(Rectangle::new(128.0, 128.0))) .into(), material: materials.add(ColorMaterial::from(Color::WHITE)), ..default() }, MyIntervalProperty(IntervalProperty::new( (Vec2::new(-250.0, -250.0)..=Vec2::new(250.0, 250.0)).into(), 0.5, )), )); }