is it possible to detect a touch input within a certain screen part?
for example:
can i detect a swipe inside are A and a pinch inside zone B?
is it possible to detect a touch input within a certain screen part?
for example:
can i detect a swipe inside are A and a pinch inside zone B?
1.Create a Quad with a collider that fit to the touchable area as it facing the MainCamera. And turn off the Mesh Renderer.
Use the following logic to implement the swiping gesture.
bool isTouchableArea = false;
void Update()
{
if (Input.touchCount > 0)
{
if(Input.GetTouch(0).phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
//Debug.Log(ray.origin);
RaycastHit hit;
if(Physics.Raycast(ray,out hit))
{
//Debug.Log("Ray Catsed");
if(hit.collider!=null && hit.collider.name=="Quad")
{
//Debug.Log(hit.collider.name);
isTouchableArea = true;
}
}
else
{
isTouchableArea = false;
}
}
if(isTouchableArea && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
Debug.Log(touchDeltaPosition);
rigidbody.velocity = touchDeltaPosition;
}
}
}