If you know both points of the line you can simply use Physics2D.Linecast. Including that, either a Raycast or CircleCast will all work depending on how you want to detect the ball. [Raycast][2] is a laser shot in a direction over a distance (its length). [Linecast][1] is a line from start to end. [CircleCast][3] is a circle (ball size) shot in a direction over a distance (length).
[1]: https://docs.unity3d.com/2018.4/Documentation/ScriptReference/Physics2D.Linecast.html
[2]: https://docs.unity3d.com/2018.4/Documentation/ScriptReference/Physics2D.Raycast.html
[3]: https://docs.unity3d.com/2018.4/Documentation/ScriptReference/Physics2D.CircleCast.html
↧