title: Unity: Problem with Index was outside the bounds of the array
body: <p>I'm drawing using LineRenderer but I enable and disable the gameobject where the script is at different times.</p>
  
  <p>The first enable it works perfect, after I disable and enable, I get this error</p>
  
  <blockquote>
    <p>IndexOutOfRangeException: Index was outside the bounds of the array.</p>
  </blockquote>
  
  <p>error shows to this line of code</p>
  
  <pre><code>Vector2 touchPos = Camera.main.ScreenToWorldPoint(Input.touches[0].position);
  </code></pre>
  
  <p>Here is all the code</p>
  
  <pre><code>public GameObject linePrefab;
  private Line activeLine;
  
  private void Update()
  {
      if (Input.touchCount &gt; 0)
      {
          if (Input.GetTouch(0).phase == TouchPhase.Began)
          {
              GameObject lineGO = Instantiate(linePrefab);
              activeLine = lineGO.GetComponent&lt;Line&gt;();
          }
  
          if (Input.GetTouch(0).phase == TouchPhase.Ended)
          {
              activeLine = null;
          }
      }
  
      if (activeLine != null)
      {
          Vector2 touchPos = Camera.main.ScreenToWorldPoint(Input.touches[0].position);
          activeLine.UpdateLine(touchPos);
      }
  }
  </code></pre>