Detect object between two object

I am working on 2d game where you will connect line between two object and if any third object is available between this than it will notify?

For example if i am connecting c and m by mouse click then mt should be detect.How can i implement this and is this possible by raycasting?

I would recommend using LineCast (you simply enter the two points), not RayCast (you enter a point and direction, more useful for e.g. shooting from a gun).

Look up

You can use a layer mask to make sure only certain objects (the ones with the corresponding sorting layer) get picked up. Please note the difference between sorting layers (for 2D) and regular layers (for other things such as the Camera).