OnTriggerEnter Error, This has to be of Type Collider2D

I have a shield for my character, and I don’t want it actually interacting with the physics, but I want it to detect enemies or enemies’ attack triggers. So, I turned it into a trigger,

    private void OnTriggerEnter2D(Collision2D collision)
    {
        if (collision.collider.CompareTag("Enemy") || collision.collider.CompareTag("AttackTrigger") && !blockHitter)
        {
            StartCoroutine(BlockHit());
        }
    }

But I get an error, “This has to be of Type Collider2D”

Does anyone know how to fix this?

Thanks

Change
(Collision2D collision)
to
(Collider2D collision)

1 Like

I’ve tried that, it just says

'Component.collider' is obsolete: 'Property collider has been deprecated. Use GetComponent<Collider>() instead.

collision.collider.CompareTag("Enemy")
to
collision.CompareTag("Enemy")
same for “AttackTrigger”.

1 Like

Ah, that fixed it haha. Thank you very much