Problem with Input.GetMouseButtonUp(0) and Macbook Pro touchpad.,Problem with Input.GetMouseButtonUp(0) on Macbook touchpad
Hello,
I have searched the net but could not find a similar problem so I am hoping there are improvement I could add to the code to fix this problem.
My problem is that the left click when tapping lightly on the touchpad lacks consistency when returning true from the Input.GetMouseButtonUp(0). It usually takes couple of taps for it to return true and select my unit. However when actually clicking and not tapping either with touchpad or mouse it works 100% of the time. I am wondering where this kind of inconsistency would come from. I'd be happy to know your ideas! The code in C# can be seen in FIG 1.
Couple of points: - I am not using FixedUpdate, everything is happening in Update. Otherwise regular clicking would have problems as well I'd imagine. - I cannot use GetMouseButtonDown or GetMouseButton because they are reserved for dragging the camera. I don't want units deselecting when dragging the camera! - Not sure why, but switching the execution order of the elseif-chain and adding additional bool which does not let GetMouseButtonDown activate if camera is dragging did not fix it (FIG 2). Thus I feel like the inconsistent connection between tapping on the touchpad and triggering GetMouseButtonUp might be internal.
FIG 1:
void Update () {
if (Input.GetMouseButtonDown (0)) {
// Left mouse button just went down. This doesn't do anything yet.
}
else if (Input.GetMouseButtonUp (0)) {
// If we are clicking a tile with a unit, select it.
if (tileUnderMouse.unit != null) {
selectedUnit = tileUnderMouse.unit;
cbUnitSelected (selectedUnit);
}
// Else deselect anything that was selected.
else {
selectedUnit = null;
cbUnitSelected (selectedUnit);
}
}
else if (Input.GetMouseButton (0) &&
Vector3.Distance (currFrameMousePosition, lastFrameMousePosition) > mouseDragThreshold) {
// Left button is held down and the mouse moved an appropriate amount: start camera drag.
Update_CameraDrag ();
}
}
FIG 2: void Update () {
if (Input.GetMouseButton (0) &&
Vector3.Distance (currFrameMousePosition, lastFrameMousePosition) > mouseDragThreshold) {
// Left button is held down and the mouse moved an appropriate amount: start camera drag.
isDragging = true;
UpdateCameraDrag ();
}
else if (Input.GetMouseButtonDown (0)) {
if (isDragging == true) {
return;
}
// If we are clicking a tile with a unit, select it.
if (tileUnderMouse.unit != null) {
selectedUnit = tileUnderMouse.unit;
cbUnitSelected (selectedUnit);
}
// Else deselect anything that was selected.
else {
selectedUnit = null;
cbUnitSelected (selectedUnit);
}
}
}
Thank you very much for your time!
Simon
Your answer
Follow this Question
Related Questions
Monodevelop 4.0.1 strange font on Mac El Capitan 0 Answers
Could I access to finder osx label color ? 0 Answers
Calling functions from Native DLL (C++) inconsistently crashes Unity 1 Answer
Unity on Mac get Error 500 while trying to activate Personal Edition license 1 Answer
Android Touchpad - Registering touch on whole screen 1 Answer