This repository was archived by the owner on Mar 4, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 176
This repository was archived by the owner on Mar 4, 2025. It is now read-only.
Support for Text2dBundle #358
Copy link
Copy link
Open
Description
Any ideas why this isn't working?
use bevy::prelude::*;
use bevy::text::Text2dBounds;
use bevy_mod_picking::prelude::*;
pub fn run () {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, setup)
.run();
}
#[derive(Component)]
struct ClickableText;
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// Camera
commands.spawn(Camera2dBundle::default());
let font = asset_server.load("fonts/OpenSans-Regular.ttf");
let text_style = TextStyle {
font,
font_size: 30.0,
color: Color::WHITE,
};
commands.spawn((
Text2dBundle {
text: Text::from_section(
"Click me!",
text_style,
),
text_2d_bounds: Text2dBounds {
size: Vec2::new(300.0, 100.0),
},
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
},
PickableBundle::default(),
On::<Pointer<Click>>::run(on_click),
ClickableText,
));
}
fn on_click(
event: Listener<Pointer<Click>>,
query: Query<&Text, With<ClickableText>>
) {
println!("Not firing");
if let Ok(text) = query.get(event.target) {
println!("Clicked text: {}", text.sections[0].value);
}
}
Metadata
Metadata
Assignees
Labels
No labels