R
R
realmadness2020-03-26 00:17:43
2D
realmadness, 2020-03-26 00:17:43

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...5e7bc9e4294bf141942314.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Muravyov, 2020-03-26
@realmadness

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);
        }
    }

Where tag is the tag of your all clones

E
Evgeny Zaletsky, 2020-03-26
@JZ_52

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 question

Ask a Question

731 491 924 answers to any question