How to damage all objects in a line

Hi I’m creating a tower defense game and I’m kinda stuck on the rail gun(It’s a tower that damages all the enemies in a straight line). I have modified the beam tower’s lazer to be a continuous line rather then stopping after coming in contact with the first enemy(
if(beamLength>=dist){
lineRenderer.SetPosition(1, (target.thisT.position-thisT.position)*100);}
}
), but I can only seem to damage the first object that is hit. should i use a collider? and if i should how so? or should i use raycast all?
thanks in advance for any help.

If you use RaycastAll, you will get all of the objects that are hit, this will give you the list of objects to damage.