using UnityEngine using System Collections public class DragByTouch Mo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using UnityEngine;
using System.Collections;
public class DragByTouch : MonoBehaviour
{
void Update()
{
foreach (Touch touch in Input.touches)
{
Collider2D collider = Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(touch.position));
if (collider == null) return;
switch (touch.phase)
{
case TouchPhase.Began:
collider.gameObject.SendMessage("TouchBegan");
break;
case TouchPhase.Canceled:
collider.gameObject.SendMessage("TouchEnded");
break;
case TouchPhase.Ended:
collider.gameObject.SendMessage("TouchEnded");
break;
case TouchPhase.Moved:
collider.gameObject.SendMessage("TouchMoved", touch);
break;
}
}
}
}