Hi, I have this code set up to see if my finger is touching an object on my ipad. Whenever the object is touched, I call for a method to destroy it, add points, etc…
The problem is, that the method is getting called more than once (its getting called for every prefab that has the tag “burbuja”)… I don’t get it, the raycast is only colliding with one, so why is the method being called for every other collider that is not getting touched?
RaycastHit hit = new RaycastHit();
for (int i = 0; i < Input.touchCount; ++i)
{
if (Input.GetTouch(i).phase.Equals(TouchPhase.Began))
{
// Construct a ray from the current touch coordinates
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
if (Physics.Raycast(ray, out hit))
{
if(hit.collider.gameObject.tag=="Burbuja")
{
DestruirBurbuja(hit.collider.gameObject);
}
}
}
}