- Home /
IOS object touch, collider
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);
}
}
}
}
Answer by Vollmondum · Oct 21, 2012 at 04:52 AM
If you change
if(hit.collider.gameObject.tag=="Burbuja")
to
if(hit.collider.gameObject.name=="Burbuja(Clone)")
It would work. I had same problem before using tags. With names it's okay.