Find the distance between the player and a path?

In a 3D world, the player has the option to go anywhere, for the most part. I want to add an effect such as a flashlight flickering out, and monsters start attacking the player whenever the player goes a certain distance away from the path.

Is there anyway to create a line that follows my path and to detect the closest part of the path to the player? I’m sort of new to unity and i cant think of any other way besides making a bunch of hidden objects and iterating through them to find the closest and then check to see if its too far away.

Thanks!

I would try it with Vector3.Distance(); or Collider.