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;
}
}
}
}
}