Detecting in view entity's

So in my game (With a plants vs zombies style) my towers are placed in rows, and the enemy’s walk on these rows too. Right now I have it so my towers attack if an enemy is on screen at all. But I want to change it to reduce lag, so that they only fire if the enemy’s are in the same row

Does anyone know how to detect that?

Why not have your towers send a raycast before they attack, and skip the attack unless the ray hits an enemy?

Thank you so much, I never knew how to use Ray-Cast