N
N
Nikolai Getmanov2020-05-19 09:15:59
Unity
Nikolai Getmanov, 2020-05-19 09:15:59

Destroy doesn't work. Why is that?

I'm making a simple platformer where you need to collect stars on Unity. When a character touches a star, the star does not disappear. I send a function where Destroy does not work.

Note: Is Trigger in collider set.

void OnTriggerEnter2D(Collider2D col)
    {
        if (col.GetComponent<PolygonCollider2D>().tag == "star")
        {
            Destroy(col.gameObject);
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-05-19
@Kolya_Get

Well, for example, because if is not executed. Debugger in the teeth and go

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question