I have two objects with a line going from one to the other, like this:
I want to create another line with a starting point one of the objects and an end point the mouse position, however still facing the second object, which will look like the first line is filling up to where the mouse is.
For example, I want to connect the blue shape with the green shape, so I move my mouse from one to the other. The game finds the nearest white line from the cursor and creates another line on top of it that follows my cursor, like this:
The current script is this. It draws a line from the origin shape to the mouse position, but it doesn't stay on only one direction and instead moves where my mouse goes:
public class SelectionLine : MonoBehaviour {
private LineRenderer lineRenderer;
private void Awake() {
lineRenderer = GetComponent<LineRenderer>();
}
private void Update() {
if (ShapeSelection.instance.selectedShape != null && ShapeSelection.instance.draggingFinger != null) {
var originPosition = ShapeSelection.instance.selectedShape.transform.position;
var destinationPosition = ShapeSelection.instance.draggingFinger.ScreenPosition;
lineRenderer.SetPosition(0, new Vector2(originPosition.x, originPosition.y));
lineRenderer.SetPosition(1, new Vector3(ShapeSelection.instance.draggingFinger.GetWorldPosition(1f).x, ShapeSelection.instance.draggingFinger.GetWorldPosition(1f).y, 0));
}
}
}
There is no way (as far as I know) to set a direction of a line renderer in Unity, so how can I achieve this?