I am using
void Update()
{`for (var i = 0; i < Input.touchCount; ++i)
{
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
// Construct a ray from the current touch coordinates
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
if (Physics.Raycast(ray))
Destroy();
}
}
}
I tested on my mobile phone (Windows Phone) to see if I can touch my object to destroy. This script is also attached to the object, so when touched it should get destroyed. Instead, if I touch anywhere in the screen, all the objects, which is multiple duplicates of one object, gets destroyed instead of the specific one I touch. This does not happen when I use OnMouseDown. Is there something I can do similar to MouseDown with touch control?