New to bevy and need to implement a double click system into my game and this is what I tried. I got a couple errors specifically relating to the local variable containing Instant. I have properly imported the instant crate but am not sure what else is needed in bevy to make a local var work.
pub fn double_click(
mouse_button_input: Res<Input<MouseButton>>,
mut double_click_time: Local<Instant>,
) {
if mouse_button_input.just_pressed(MouseButton::Left) {
double_click_time = Instant::now();
}
println!("Time: {}", double_click_time.elapsed().as_secs());
}
One error I am getting is at the Instant::now();
and it is
expected struct `bevy::prelude::Local<'_, Instant, >`
found struct `Instant
Also where the system is added it gives error
the trait bound `for<'r, 's> fn(bevy::prelude::Res<'r, bevy::prelude::Input<bevy::prelude::MouseButton>>, bevy::prelude::Local<'s, Instant>) {inventory::double_click}: IntoSystem<(), (), _>` is not satisfied
If there is another way to detect a double click, that works too!
Based on your error and the docs for Local
(which say that it implements Deref
and DerefMut
), you just need to assign to the contents of the Local
, and that should fix your compile error:
*double_click_time = Instant::now();
I don't know Bevy, so I don't know if this is actually the best way to handle double clicks.