I have two prefabs spawned at the different position, both are having same script . Now I need to destroy the prefabs if they are touched at the same time. Is there any easiest way to do this?
Note: both the prefabs are having collider2D attached to it. And also multi touch is enabled.
Thanks!
This is the code which enabled multitouch
if (Input.touchCount > 0)
{
foreach (Touch t in Input.touches)
{
Debug.LogError("current touch "+Input.touches);
Debug.LogError("touch count is "+Input.touchCount);
Vector3 touchPos = t.position;
if(t.phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(touchPos);
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);
if (hit.collider != null && hit.transform == transform)
{
Debug.Log("Hit: " + hit.transform.name);
myOnMouseDown(); //This function will be resposible for destroying the prefab
break;
}
}
}
}