One way to do it is to use the bounding box between the two points. As stated here:
An axis-aligned bounding box, or AABB for short, is a box aligned with coordinate axes and fully enclosing some object. Because the box is never rotated with respect to the axes, it can be defined by just its center and extents, or alternatively by min and max points.
I have written a simple code for you to show how it works (the gizmos code is from here), if you want more complex shapes you can use multiple bounding boxes (moreover, you can create your path using the probuilder package, disable the shape and just use the collider of it)
[SerializeField] private Transform startTransform;
[SerializeField] private Transform endTransform;
[SerializeField] private Transform plane;
[SerializeField] private Vector3 size = Vector3.one * 3.5f;
[SerializeField] private Bounds _bounds;
private void Start()
{
_bounds = new Bounds {center = (startTransform.position + endTransform.position) / 2,extents = size};
}
private void Update()
{
print(_bounds.Contains(plane.position) ? "yes" : "no");
}
private void OnDrawGizmos()
{
var xVals = new[]
{
_bounds.max.x, _bounds.min.x
};
var yVals = new[]
{
_bounds.max.y, _bounds.min.y
};
var zVals = new[]
{
_bounds.max.z, _bounds.min.z
};
for (int i = 0; i < xVals.Length; i++)
{
var x = xVals[i];
for (int j = 0; j < yVals.Length; j++)
{
var y = yVals[j];
for (int k = 0; k < zVals.Length; k++)
{
var z = zVals[k];
var point = new Vector3(x, y, z);
Gizmos.DrawWireCube(point, _bounds.extents);
if (i == 0)
{
Gizmos.DrawLine(point, new Vector3(xVals[1], y, z));
}
if (j == 0)
{
Gizmos.DrawLine(point, new Vector3(x, yVals[1], z));
}
if (k == 0)
{
Gizmos.DrawLine(point, new Vector3(x, y, zVals[1]));
}
}
}
}
}