title: How to update line renderer's start and end positions at runtime?
body: <p>I'm trying to connect two GameObject (<strong>sphereObject0</strong> and <strong>sphereObject2</strong>) with a line renderer <strong>lineRenderer0_2</strong> in a Unity3D project.</p>
  
  <p>The line shows up fine at first. My problem is that I need the line renderer to update its start and end positions to match the positions of <strong>sphereObject0</strong> and <strong>sphereObject2</strong>.</p>
  
  <p>For some reasons, my line renderer is absolutely static, and I can't find the way to make it adjust its start and end positions together with the spheres GameObjects eventually move around.</p>
  
  <p>Here's my C# script, any idea about what I am doing wrong? Any help is greatly appreciated!</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class autoCreateNetwork : MonoBehaviour {
  
      public bool sphereHasGravity = false;
      private Collider coll;
      private Renderer rend;
      private SpringJoint springJoint;
      public Material lines;
  
      GameObject sphereObject0;
      GameObject sphereObject2;
      LineRenderer lineRenderer0_2 ;
  
      void Start () {
  
          // Spawn a sphere and set it up
          sphereObject0 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
          sphereObject0.transform.position = new Vector3(-10.2571400951f, 98.8977277884f, -19.9870244083f);
          Rigidbody sphereBody0 = sphereObject0.AddComponent&lt;Rigidbody&gt;();
          sphereBody0.mass = 1f;
          // Physics model
          coll = sphereBody0.GetComponent&lt;Collider&gt; ();
          PhysicMaterial material0 = new PhysicMaterial();
          material0.dynamicFriction = 1;
          coll.material = material0;
          coll.material.bounciness = .8f;
          // Render (color, smoothness, etc.)
          rend = sphereBody0.GetComponent&lt;Renderer&gt;();
          rend.material.color = new Color32(171,166,164,255);
          rend.material.SetFloat("_Metallic", 0.0f);
          rend.material.SetFloat("_Glossiness", 0.0f);
          sphereBody0.useGravity = sphereHasGravity;
          sphereBody0.transform.localScale = new Vector3(0.5f,0.5f,0.5f);
  
          // Spawn a sphere and set it up
          sphereObject2 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
          sphereObject2.transform.position = new Vector3(-28.1943570987f, 89.5665878403f, 5.43686642264f);
          Rigidbody sphereBody2 = sphereObject2.AddComponent&lt;Rigidbody&gt;();
          sphereBody2.mass = 1f;
          // Physics model
          coll = sphereBody2.GetComponent&lt;Collider&gt; ();
          PhysicMaterial material2 = new PhysicMaterial();
          material2.dynamicFriction = 1;
          coll.material = material2;
          coll.material.bounciness = .8f;
          // Render (color, smoothness, etc.)
          rend = sphereBody2.GetComponent&lt;Renderer&gt;();
          rend.material.color = new Color32(105,150,187,255);
          rend.material.SetFloat("_Metallic", 0.0f);
          rend.material.SetFloat("_Glossiness", 0.0f);
          sphereBody2.useGravity = sphereHasGravity;
          sphereBody2.transform.localScale = new Vector3(0.5f,0.5f,0.5f);
  
          // Spawn a line and set it up
          GameObject line0_2 = new GameObject();
          LineRenderer lineRenderer0_2 = line0_2.AddComponent&lt;LineRenderer&gt;();
          lineRenderer0_2.material = lines;
          lineRenderer0_2.widthMultiplier = 0.0482773661501f;
          lineRenderer0_2.SetPosition(0, sphereObject0.transform.position);
          lineRenderer0_2.SetPosition(1, sphereObject2.transform.position);
          float alpha0_2 = .9f;
          Gradient gradient0_2 = new Gradient();
          gradient0_2.SetKeys(
              new GradientColorKey[] { new GradientColorKey(new Color32(171,166,164,255), 0.0f), new GradientColorKey(new Color32(105,150,187,255), 1.0f) },
              new GradientAlphaKey[] { new GradientAlphaKey(alpha0_2, 0.0f), new GradientAlphaKey(alpha0_2, 1.0f) }
          );
          lineRenderer0_2.colorGradient = gradient0_2;
          lineRenderer0_2.useWorldSpace = true;
  
      }
  
      void Update () {
  
              lineRenderer0_2.SetPosition(0, sphereObject0.transform.position);
              lineRenderer0_2.SetPosition(1, sphereObject2.transform.position);
  
          }
      }
  </code></pre>