TouchCount always > 0 on Android

I’m working with Unity/Android for the first time. I have several objects on the screen all with the same script on each. I want to be able to independently drag each object around. This works fine when I test it in the game tab, but when I actually build on Android it doesn’t work correctly. Instead, after touching an object once, anytime I touch the screen anywhere else it instantly jumps there. Not just when I drag. Could anyone tell me what i’m doing wrong (and maybe a few other tips? I know the way i’m doing this isn’t the best…)

using UnityEngine;
using System.Collections;


public class handleTouch : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame

	public bool dragging = false;
	void Update()
	{
		var aTouch = Input.GetMouseButton(0);
		var touchPos3D = Input.mousePosition;
		var firstTouch = false;

		if (Application.platform != RuntimePlatform.IPhonePlayer && Application.platform != RuntimePlatform.Android)
			
		{
			if (Input.GetMouseButtonDown(0)){
				firstTouch = true;
			}
		} 
		else 
		{
			aTouch = (Input.touchCount > 0);
			touchPos3D = Input.touches[0].position;

			if (Input.touches[0].phase != TouchPhase.Moved){
				firstTouch = true;
			}
		}

		if (aTouch)
		{
			Vector3 wp = Camera.main.ScreenToWorldPoint(touchPos3D);
			Vector2 touchPos2D = new Vector2(wp.x, wp.y);

			
			if (this.collider2D == Physics2D.OverlapPoint(touchPos2D) && firstTouch == true)
			{
				dragging = true;
			}
			else
			{
				if (dragging == true)
				{
					this.transform.position = touchPos2D;
				}
			}
		}
		else
		{
			dragging = false;
		}
	}
}

I know the question is an ancient question but since it got bumped, here’s the answer:

The issue is most likely line 31 and 33 where you blindly try to access touch 0 from the touches array regardless of the touch count. This will cause an index out of bounds exception and no code that follow that line would run if no touch is active. Therefore when the touch count is 0 you never reach down to your code where you reset your dragging variable back to false. So when a new touch occurs you are still “dragging”.

I highly doubt that the OP still needs this information since he wasn’t seen here on UA in the last 7 years. I also doubt that the answer will be helpful to any of the necro bumpers but it may help others who actually overlooked the fact that the touches array can be empty.