using UnityEngine using System Collections using System Collections Ge

 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
34
35
36
37
38
39
40
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MultiTouch : MonoBehaviour
{
private Dictionary<int, GameObject> Objects = new Dictionary<int, GameObject>();
void Update()
{
foreach (Touch touch in Input.touches)
{
switch (touch.phase)
{
case TouchPhase.Began:
Collider2D collider = Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(touch.position));
if (collider != null)
{
Objects.Add(touch.fingerId, collider.gameObject);
Objects[touch.fingerId].SendMessage("OnTouchBegan", SendMessageOptions.DontRequireReceiver);
}
break;
case TouchPhase.Canceled:
Objects[touch.fingerId].SendMessage("OnTouchEnded", SendMessageOptions.DontRequireReceiver);
Objects.Remove(touch.fingerId);
break;
case TouchPhase.Ended:
Objects[touch.fingerId].SendMessage("OnTouchEnded", SendMessageOptions.DontRequireReceiver);
Objects.Remove(touch.fingerId);
break;
case TouchPhase.Moved:
Objects[touch.fingerId].SendMessage("OnTouchMoved", touch, SendMessageOptions.DontRequireReceiver);
break;
}
}
}
}