- Home /
Differentiate left, right and both mouse inputs
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!
There are many ways how you can approach this, and it depends on what kind of outcome you desire. Just to give you an idea, you could only use the left and right mouse click, when you release the button ( Input.GetMouseButtonUp(0)
) When you release, you check if you currently hold down the other button (in this case Input.GetMouseButton(1)
), and if this is the case, then you detect it as "both clicked" else; "Do MouseButton(0)-Stuff". Then you also need to code this the other way around, to detect "MouseButton(1)-Stuff". This would be a quick solution. But I don't think this would not feel so great in practice. I like your timer idea, and I would says that this is the way to go.
Your answer
Follow this Question
Related Questions
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Strange Input.GetMouseButtonDown behaviour 1 Answer
Unity sometimes misses Mouse Button Release 1 Answer
Detect mouse clicks anywhere on the screen except given gameobject 2 Answers
Touch and MouseClick - One Game for Mobile and Desktop 3 Answers