So, I'm working on an Android game at my job, and I came across a curious anomaly where objects (with colliders attached, of course) seemed to react to single finger presses as if they were pressed multiple times instead. I spent a while manually debugging by means of Debug.Log and the PC-based Android debugger, and after looking hard enough I finally spotted what appears to be the problem: Unity's OnMouseDown event is being called multiple times in the same frame!
The fix was simple but somewhat counter-intuitive:
Did anything like this happen to anyone else who's using Unity for Android? I'm mostly wondering if it's merely a problem with the specific phone model and build I'm using for testing (a Motorola Milestone 1) or a more widespread one.
The fix was simple but somewhat counter-intuitive:
Code:
private bool mouseDownRegistered = false;
private void OnMouseDown() {
if (mouseDownRegistered) return;
mouseDownRegistered= true;
//OnMouseDown event code goes here
}
private void LateUpdate() {
if (mouseDownRegistered) mouseDownRegistered= false;
}
Did anything like this happen to anyone else who's using Unity for Android? I'm mostly wondering if it's merely a problem with the specific phone model and build I'm using for testing (a Motorola Milestone 1) or a more widespread one.