Recalculate linerenderer when moving gameobjects

Hi!

I’m creating spheres that are linked between then using a linerenderer. What I need, and I don’t know how to do it, is to “update” the linerenderer just when one of the spheres moves. This is my code:

[SerializeField] GameObject[] spheres;
[SerializeField] GameObject link;
private LineRenderer lineRenderer;

private void Awake () {
    lineRenderer = link.GetComponent<LineRenderer>();
    lineRenderer.positionCount = 2;
}

private void Start () {
    CreateShape();
}

private void CreateShape ()
{
    for (int i = 0; i < spheres.Length; i++)
    {
        for (int j = i + 1; j < spheres.Length; j++)
        {
            link.name = spheres[j].transform.name;
            lineRenderer.SetPosition(0, spheres*.transform.position);*

lineRenderer.SetPosition(1, spheres[j].transform.position);
Instantiate(link, Vector3.zero, Quaternion.identity, spheres*.transform);*
}
}
}

Hello.

Where is the problem? If you get to correctly create the line, you only need to update the points.

Every time a sphere moves, you need to use lineRenderer.SetPosition again with the neew positions. As you do it refering directly the sphere , just do this again in update, or every time a sphere is moving

         lineRenderer.SetPosition(0, spheres*.transform.position);*

lineRenderer.SetPosition(1, spheres[j].transform.position);
Bye!