How to draw a line like this? (3D)

(3D) How can I do a mechanic like this? At first I’ve tried to do raycast that follows my mouse but I failed. So I need to have a line, when I move my mouse it will follow it, but the length is until it reaches any object and in the end of the line there will be any sprite (on screenshot there is a crosshair or something)173205-screenshot-1.png

If you want to do it with a line renderer, then set the line renderer’s first position to the A position, and set the second position to the B position. This will cause the line renderer draw a line between those two points.

public LineRenderer lineRenderer;
Vector3 aPosition =;       // GameObject's tansform.position
Vector3 bPosition = new Vector3(1,1,1);//  Target's transform.position
private void Awake()
    lineRenderer = GetComponent<LineRenderer>(); // Gets the LineRenderer component from the GameObject that the script is on
private void Update()
private void DrawLine()
    lineRenderer.SetPosition(0, aPosition); // Sets the line's first position to the first GameObject
    lineRenderer.SetPosition(1, bPosition); // Sets the line's second position to the target's position

I hope it works.

You can set the line material, the width and other parameters in the inspector.