Get collision from another object?

I have object A and Object B


object A should disable with a buttonpress collision of objectB.
And It works well.


I have as variable:

[SerializeField] Collider2D c;  

if (Some button is pressed) c.enabled = false;


I just want to know how to access the collider without using SerializeField.
I tried with
c = objectB.GetComponent<Collider2D>(); But it didn’t worked.

Check out your reference to object but
c = objectB.GetComponent<Collider2D>();
should work… But if it’s a circle collider or a box collider you should use
c = objectB.GetComponent<BoxCollider2D>();
or
c = objectB.GetComponent<CircleCollider2D>();