G
G
G3ntl3m3n2017-04-30 14:08:24
2D
G3ntl3m3n, 2017-04-30 14:08:24

How to remove coins on collision?

2D game. When a player collider collides with a coin collider, it should be removed and coins added to the player
. I write:

private void Coins()
    {
        if(gameObject.name == "Coin")
        {
            coins++;
            Destroy(gameObject);
        }
    }

and doesn't work.
Everything is handled in the Character Controller.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pparma, 2017-04-30
@G3ntl3m3n

See any tutorial on handling collider collisions.
And it is better not to delete the coins, but to hide them and then reuse them. The constant generation and deletion of objects of the same type is a useless load.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question