Answer the question
In order to leave comments, you need to log in
How to delete an object when a character collides with it?
Hello, please help... I made a random appearance of objects (clones drop out from it). How can I make it so that when a character collides with this clone, the clone disappears? It is necessary that the clone that was in contact with the character disappear (not all clones at once). I only succeeded in such a way that
all the objects that the character touched disappeared, even the ground, under the character himself...
Answer the question
In order to leave comments, you need to log in
You wrote the contact test method correctly, now write it like this:
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("tag"))
{
Destroy(collision.gameObject);
}
}
If this is a 2D game, then everyone has a certain regidbody and there you do a check, if you touched it, then grandfather.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question