I am trying to see where the mouse is pressed so I can select my character. I have tried the following
#[derive(Default)]
struct State { // Set up from example
mouse_button_event_reader: EventReader<MouseButtonInput>,
cursor_moved_event_reader: EventReader<CursorMoved>,
}
fn select_character(
mut state: ResMut<State>,
mouse_button_input_events: Res<Events<MouseButtonInput>>,
cursor_moved_events: Res<Events<CursorMoved>>,
) {
for (cursor_event, mouse_event) in state
.cursor_moved_event_reader
.iter(&cursor_moved_events)
.zip(
state
.mouse_button_event_reader
.iter(&mouse_button_input_events),
)
{
println!("{:?}", cursor_event);
println!("{:?}", mouse_event);
}
}
This kind of works, but the mouse needs to be moving while it is clicked. Is there a way of getting the position once the mouse is pressed?
Edit:
I thought .find_latest
might work, getting it to return the latest Some
value.
for event in state
.mouse_button_event_reader
.iter(&mouse_button_input_events)
{
let cursor_event = state
.cursor_moved_event_reader
.find_latest(&cursor_moved_events, |x| x.is_Some() // Not sure how to only return values that are Some(x)
);
println!("{:?}", event);
println!("{:?}", cursor_event);
}