[Bug?] OnMouseDown() works on touch devices

Hello everyone!

I’ve run into some annoying OnMouseDown() function behaviour on iOS devices in Unity 4 (I assume it works the same on Android devices).

There’s a basic scene with few cubes on it. Each cube has this script attached to it:

using UnityEngine;
using System.Collections;

public class SimpleClickScript : MonoBehaviour {
	void OnMouseDown() {
		Destroy(gameObject);
	}
}

When I run this scene on actual device, the OnMouseDown function works! Even though in official Unity documentation it states that:

(Unity - Scripting API: MonoBehaviour.OnMouseDown())

But the problem is that when you click on few objects with two or more fingers at once wrong game objects are being destroyed. Here’s a video of what happens:

Also tried to run this scene with this code on each cube instead:

using UnityEngine;
using System.Collections;

public class RaycastClickScript : MonoBehaviour {
	void Update () {
		if (Input.GetMouseButtonDown(0)) {
			RaycastHit hit = new RaycastHit();
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			if (Physics.Raycast(ray, out hit)) {
				hit.transform.gameObject.SendMessage("ClickHandler");
			}
		}
	}
	
	public void ClickHandler() {
		Destroy(gameObject);
	}
}

Result is the same. Any idea why this might be happening?

You can download source project ZIP here: http://d.pr/f/NWEA

Thanks in advance,

Kostya

Guys, have anyone else experienced this problem? Really need help with this :frowning:

The same on Android, but it is not a problem for me on my own case, on the contrary…

Anyway you can try to ignore these events depending on the underlying device. This may help to detect it:

http://forum.unity3d.com/threads/75101-Device-detection-computer-vs-iOS

Thanks for the tip, Marzoa!