Search Unity

Differentiate left, right and both mouse inputs

Discussion in 'Input System' started by TimeForToast, May 3, 2021.

  1. TimeForToast

    TimeForToast

    Joined:
    Apr 29, 2019
    Posts:
    2
    Hello everyone!

    I'm trying to create an inputmanager for a game that checks three inputs: leftclick, rightclick and both buttons clicked at the same time. I have that much set up, but i have to press left and rightclick on the exact same frame for it to work for the double click. I have an idea of how to resolve this, though I'm doubtful if it would be the most efficient way.

    What I need to do is check if either left or right click is pressed then start a short timer of a few frames, within that period i check if either of the other buttons is pressed. If that's the case, then it sets the double click to true. But I also don't want the left and right button input to do anything before this condition has been checked.

    The way I'm imagining it is just a whole set of if loops and bools, and considering my coding skills are limited, I thought there might be someone out there that could teach me a more efficient and cleaner system of establishing this.

    Thank you in advance!
     
  2. Marconius6

    Marconius6

    Joined:
    Mar 4, 2021
    Posts:
    8
    The main problem with waiting for some time before doing anything is it will make regular left or right clicks a bit laggy, since it will have to wait for the timeout every time. This might make your interface feel very sluggish, even if you set the timer fairly short.

    Your suggestion is probably the best way to actually do it, but I'd have a discussion with your UX designer about this in the first place.
     
    chunnomi_monnaka likes this.
  3. jukibom

    jukibom

    Joined:
    Aug 31, 2015
    Posts:
    54
    Best advice I could give for this is to set the mouse binding Action Type as Value rather than Button. That way, when you handle the input you can use InputValue.IsPressed and the event will fire on mouse button down and mouse button up. This gives you a bit more flexibility as you likely want to handle a genuine independent left or right click once the user lets go of the button (at least for selection interactions rather than, say, shooting a gun). At least this way if the user clicks and releases within 1 frame then you can handle that with minimum latency.

    Other than that, I suspect you're on the right path having some kind of fuzzy logic to detect both clicks at once.