How to compare position values in Input table

Hi, In my application I locate the position of the screen touches. I would like to calculate the distance between touches by comparing each one and if say the distance is more than 300 pixels then display an image or do some action. Currently I am able to compare two positions between each other but I don’t know how to do it for all positions, that is whenever a new touch appears compare it with previous ones if the distance is not more than 300.

using UnityEngine;
using UnityEngine.UI;

public class TouchPosition : MonoBehaviour
{
    public Text distanceText;
    public float distance;

    void Update()
    {
        CheckDistance();
    }

    public void CheckDistance()
    {
        foreach (Touch touch in Input.touches)
        {
           
            for(int i = 0; i < Input.touchCount; i++)
            {
                Vector2 touchPosition = Input.touches*.position;*

if(i > 1)
{
float positionDistance;
Vector2 touchPosition2 = Input.touches[i-1].position;
positionDistance = Vector2.Distance(touchPosition, touchPosition2);
distanceText.text = " Distance : " + positionDistance;
}
}
}
}
}

In your code you’re iterating over the touches in the foreach loop but then not actually using the touch variable at all. I think you realise you need a double loop but you just haven’t implemented it correctly. Is something like this what you’re looking for?

using UnityEngine;

public class TouchPosition : MonoBehaviour {
  public float distance;
  void Update() {
    CheckDistance();
  }

  public void CheckDistance() {
    // You can start this loop from 1 because if you only have 1 touch there's nothing to do.
    for (int i = 1; i < Input.touchCount; i++) {
      // Loop over other touches upto but not including this one
      for (int j = 0; j < i; j++) {
        float dist = Vector2.Distance(Input.touches*.position, Input.touches[j].position);*

Debug.Log($“Dist between touch {i} and {j} = {dist}”);
}
}
}
}