title: Why can't I get touch input (Unity with C#) to work?
body: <p>I'm trying to finish the Android game I've been working on. I first made to controlling mechanism using mouse, but as it needs to work with multitouch for the shot button and the aiming area, I tried converting the script to touch input according to tutorials but it doesn't seem to register any touch.</p>
  
  <p>Also, I wanted the script to record whether one of the touches, regardless of order, was placed on the area for either shot or aiming control when it begun, and place that in a Vector3 list. When respectable touch is lifted, it resets the value in that list index. Then, for example, the shooting script checks whether one of the list values is within the range of the shooting button radius, so it activates the weapon loading. It keeps telling me this error: </p>
  
  <blockquote>
    <p>ArgumentOutOfRangeException: Index was out of range. Must be
    non-negative and less than the size of the collection. Parameter name:
    index</p>
  </blockquote>
  
  <pre><code>Here are the class codes for the touch inputs and for the shooting button:
  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class TouchControls : MonoBehaviour
  
  {
      public static bool shotTime = false;
      public static List &lt;Vector3&gt; position = new List&lt;Vector3&gt;(2);
      public static bool moveTime = false;
      // Start is called before the first frame update
      void Start()
      {
          position[0] = new Vector3(0, 0, 0);
          position[1] = new Vector3(0, 0, 0);
      }
  
      // Update is called once per frame
      void Update()
      {
          for (int i = 0; i &lt; Input.touchCount &amp;&amp; i &lt; 2; i++)
          {
              Debug.Log("Touch");
              Touch touch = Input.GetTouch(i);
              Vector3 pos = Camera.main.ScreenToWorldPoint(touch.position);
              pos.z = 0;
              if (touch.phase == TouchPhase.Began)
              {
                  position[i] = pos;
              }
              if (touch.phase == TouchPhase.Ended)
              {
                  position[i] = new Vector3(0, 0, 0);
              }
          }
          Debug.Log(position[0] + position[1]);
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class ShotButton : MonoBehaviour
  {
      public static bool time = false;
      private Vector3 scale;
      // Start is called before the first frame update
      void Start()
      {
          scale = gameObject.transform.localScale;
      }
  
      // Update is called once per frame
      void Update()
      {
          {
              if (Vector2.Distance(gameObject.transform.position, TouchControls.position[0]) &lt; scale.x || Vector2.Distance(gameObject.transform.position, TouchControls.position[1]) &lt; scale.x)
              {
                  time = true;
                  gameObject.transform.localScale = scale * 0.9f;
              }
              else
              {
                  time = false;
                  gameObject.transform.localScale = scale;
              }
          }
      }
  }
  </code></pre>
  
  <p>What is wrong with the code? How can I fix it?</p>