enter image description here There is an object on it hanging Rigidbody2D, CircleCollider2D, the script itself. many clones are made from it (it turns out that all names are obgClon, tag is Ast)

It would be desirable without in the solider, with the help -

private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Ast") { Destroy(collision.gameObject, 0.5f); } } 

understand exactly what objects collided and destroy them. And it turns out that all objects are destroyed at once.

Raised to the main page by a community spirit member yesterday .

This question contains answers that can be both good and bad; the system offered them for verification.

  • Instead of a tag, you can cast or cast using GetComponent <T> (); Entry into a collision is triggered only by the one who entered into a collision. If everything is destroyed - it means that you are doing something wrong, make sure that your colliders are not inflated to the whole card ... I don’t believe that they just cause OnCollisionEnter2D all at once. Well, also, at the time of the collision, you know both objects, and you only destroy the neighbor. Is not it easier to both swat at once? Destroy (collision.gameObject); Destroy (transforn.gameObject); - test123
  • Well, still as an option - make sure that the objects are located inside the neutral parent. In no case, do not allow the nesting of your object into your copy - test123
  • @ test123 coliders are all in size and not bloated. because if you don’t handle the 'OnCollisionEnter2D' event, they fly around and quietly repel each other. Added a picture with preseser and clones. - Alexander
  • It seems to me that the trouble is that I have all the objects with one tag and name. and in the collision of any two, for some reason, everything is destroyed ... - Alexander
  • Name and tags - this is garbage, for the most part, necessary for designers. If you correctly wrote the code, the names and tags can not influence anything. You have a direct link from a sparakast object, why do you need these tags and name? There is also a bicycle option - to make a spherokast on your own, but, it will not answer the question of what exactly you did wrong. - test123 1:51 pm

1 answer 1

All ... there was a problem in the subfabs. I had an object on the stage, clones were made from it. and in the collision everything was killed. as soon as I removed from the stage and created clones through the subs, everything was decided.