How could I detect the distance of two 2d touches but only the X coordinate? Please help:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PrototypeMovement : MonoBehaviour
{
[SerializeField] Vector3 TouchPos1;
[SerializeField] Vector3 TouchPos2;
public Rigidbody rb;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Stationary)
{
Debug.Log("stationary at " + touch.position);
TouchPos1 = touch.position;
}
if (touch.phase == TouchPhase.Moved)
{
print(Vector2.Distance(TouchPos1, TouchPos2));
print("moved at" + touch.position);
TouchPos2 = touch.position;
print(touch.position);
rb.velocity = new Vector3(rb.velocity.x,rb.velocity.y,Vector2.Distance(TouchPos1, TouchPos2));
}
}
}
}