'How to convert Line-Renderer line to Mesh

I am trying to create 3D Mesh by using Line Renderer, I can now hold and move my mouse and create a line. But the problem is I want to change it to Mesh, so that it can be 3d. I found about BakeMesh but couldn't be able to use it. How would i solve that issue? I tried many ways, but couldn't understand BakeMesh logic since there is no enough documentation about it.

public class LineDrawer : MonoBehaviour
{
    public GameObject linePrefab;
    public LayerMask CantDrawOverLayer;
    private int CantDrawOverLayerIndex;

    public float linePointsMinDistance;
    public float lineWidth;
    public Gradient lineColor;

    private Line currentLine;

    [SerializeField] private GameObject test;
    

    void Start()
    {
        CantDrawOverLayerIndex = LayerMask.NameToLayer("CantDrawOver");
    }

    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            BeginDraw();
        }

        if (Input.GetMouseButton(0))
        {
            if (currentLine != null) Draw();
        }
        

        if (Input.GetMouseButtonUp(0))
        {
            EndDraw();
        }
    }

    private void BeginDraw()
    {
        currentLine = Instantiate(linePrefab, transform).GetComponent<Line>();

        currentLine.SetLineColor(lineColor);
        currentLine.SetLineWidth(lineWidth);
        currentLine.SetPointMinDistance(linePointsMinDistance);
        Debug.Log("Begin Draw is working:");
    }

    private void Draw()
    {
        Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (!Physics.Raycast(ray, out hit)) return;
        if (hit.collider != null)
        {
            currentLine.AddPoint(mousePos);
        }
        else
        {
            EndDraw();
            Debug.Log("Hit unclickable obj!");
        }
    }

    private void EndDraw()
    {
        if (currentLine != null)
        {
            if (currentLine.pointsCount < 2)
            {
                Debug.Log("NO points!");

                Destroy(currentLine.gameObject);
            }
            else
            {
                currentLine.gameObject.layer = CantDrawOverLayerIndex;
                Debug.Log("Set new layer can't draw.");

            }
        }

    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source