void OnMouseDown for mobile?

hey! i wanted to use this snippet: using UnityEngine;[RequireComponent(typeof(Collider))]public class Snappin - Pastebin.com
but somehow it doesent work on a phone - but perfect in a editor. i think that OnMouseDown at line 30 is causing the problem.
so this line:

void OnMouseDown(){
		beingDragged = true;
	}
	void OnMouseUp(){
		beingDragged = false;
		transform.position = oldPosition; // place on the last valid position
		_intersecting = 0; // stationary block do not intersect anymore
		TintRed(_intersecting); // set the tint one last time
	}

how do i have to change this to make this work on a phone?

OnMouseDown() is an old way of interaction. There is no mouse on mobile platform so interactions are handled in a different way. That’s why it works in Editor (on PC with a mouse) and does not on mobile.

In Unity 4.6 we got new UI system as well as new Event System.

So to achieve what you want you should have Event System in your scene that will send interaction events. And your interactable objects should have some way of receiving those events.

For a purposes of interaction with GameObjects you can make them have colliders (2d or 3d) and event handler components: either default EventTrigger or your own script that implement Supported Events handling.

Also you need to add a Raycaster of proper type to your camera that will send those events.

In your case the old OnMouseDown() method will be replaced by new OnPointerDown() wich works on both PC and mobile platforms.

Hope this will help you to get the idea of interaction in Unity and solve your problem. If you have any questions left, feel free to ask.

as Phones and tablets don’t have any MOUSES then OnMouseUp or OnMouseDown will not work on them … try this

void Update(){
    		if (Input.touchCount == 1) {
    			if(Input.GetTouch(0).phase == TouchPhase.Began)
    				beingDragged = true;
    			if(Input.GetTouch(0).phase == TouchPhase.Ended){
    				beingDragged = false;
    				transform.position = oldPosition;
    				_intersecting = 0;
    				TintRed (_intersecting);
    			{
    		}
}

OnMouseDown() is not available on devices because of Touch implementation. For further answer, Kindly look this answer.

Other alternative is to use methods of Input class inside the Update().

void Update () {
		if(Input.GetMouseButtonDown(0)) {
			beingDragged = true;	
		}
		else if (Input.GetMouseButtonUp (0)) {
			beingDragged = false;
			transform.position = oldPosition; // place on the last valid position
			_intersecting = 0; // stationary block do not intersect anymore
			TintRed(_intersecting); // set the tint one last time
		}

}

The modern Unity 5 way is to disregard the concept of Mouse and Touch and move to the concept of ‘Pointers’. The Standalone Input Module (Touch Input Module now deprecated) has all the methods to handle events from multiple Pointers, which include both cursor and touch input.

The Standalone Input Module is designed to work with new UI through the Event System.

To implement Dragging you can use OnDrag

Very Helpful: OnMouseDown and mobile? - Questions & Answers - Unity Discussions