I would like to be able to detect click on a wide line. I've got a function taken from there which manages to detect if a point is exactly on it, but I'd like to add some tolerance to detect click on all the rendered line.
Here is my current function, (taken from there Determine if a point is between 2 other points on a line) :
public bool PointIsOnLine(Vector2 currPoint, UILineRenderer line)
{
Vector2 point1 = line.points[0];
Vector2 point2 = line.points[1];
float dxc = currPoint.x - point1.x;
float dyc = currPoint.y - point1.y;
float dxl = point2.x - point1.x;
float dyl = point2.y - point1.y;
float cross = dxc * dyl - dyc * dxl;
if (cross != 0)
return false;
if (Mathf.Abs(dxl) >= Mathf.Abs(dyl))
return dxl > 0 ?
point1.x <= currPoint.x && currPoint.x <= point2.x :
point2.x <= currPoint.x && currPoint.x <= point1.x;
else
return dyl > 0 ?
point1.y <= currPoint.y && currPoint.y <= point2.y :
point2.y <= currPoint.y && currPoint.y <= point1.y;
}
You can access the line's thickness using line.thickness