How do I make an object stick to all other objects (2D)

How would I go about creating a script which would allow, for example, an arrow to pierce any other gameobject, like an enemy, the walls or the floor, and stick to it? I would like it if that gameobject moved, the arrows would move with it.
I’ve tried attaching OnCollisionEnter() function to my arrow script, however nothing ever happened, even my Debug.Log messages didn’t trigger once.

You could simply parent the arrow or any object to the object it hit.

You may want to pay special attention to triggers vs colliders and OnCollisionEnter vs OnTriggerEnter