Problem with destroying prefab clones

Updated on November 14, 2017 in Unity
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on November 14, 2017

Hello, I am building a simple 2D games with balloons.

The problem is when I want to destroy overlapping balloons, sometimes it works fine, but sometime more ballons are destroyed.

I want to destroy only first balloon.

Here is my code:
RaycastHit2D[] hit = Physics2D.RaycastAll(Kamera.ScreenToWorldPoint(Input.mousePosition), Kamera.ScreenToWorldPoint(Input.mousePosition));

if (hit.Length > 0)
{
if (hit[0].collider == polygonCollider)
{
Destroy(hit[0].collider.gameObject);
}
}

I have tried everything that I know but nothing works well.

  • Liked by
Reply
1 on November 14, 2017

Camera.ScreenToWorldPoint instead of Kamera will likely fix the issue.

 

on November 14, 2017

I try that and doesnt work, thank you for advice.

Show more replies
  • Liked by
Reply
Cancel