Sudhir Kotila
Sudhir Kotila

Reputation: 677

touch.phase == TouchPhase.Canceled not worked

I'm tired to handle and solve issues related to multitouch. I'm using maximum 5 touches simultaneously but when two touches are down on two objects and I moved my fingers then that both touches fired TouchPhase.Ended event but not TouchedPhase.Canceled.

I want to fire TouchPhase.Canceled when my fingers are out of those objects.

if (touch.phase == TouchPhase.Began) { 
   hitObject.GetComponent ().TouchDown (hitObject); 
}

if (touch.phase == TouchPhase.Ended) { 
   hitObject.GetComponent ().TouchExit (hitObject); 
}

if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) { 
   hitObject.GetComponent ().TouchStay (hitObject); 
}

if (touch.phase == TouchPhase.Canceled) { 
   print ("Touched canceled...."); 
   hitObject.GetComponent ().TouchExit (hitObject); 
}

Upvotes: 3

Views: 2076

Answers (1)

nqvst
nqvst

Reputation: 361

If i understand your comment correctly

Look,I have one object on my screen.I use raycast for detecting that object.in hitObject i m stored that hittedObject and when my fingure touchdown on that object then it works. if i touchup my fingure from that hitted object that is also worked.when my fingure is stayed on that object or i m move my fingure on that hitted object that is also worked. but when during moving my fingure if it is move outside that object at that time TouchPhase.Canceled event should be fired. but that can not worked . That is my issue. How can i solved it ?

and

I want to stop dragging/swapping finger (not moving) on that hitted object how can i do?

you are going to have to restrict the swiping based on the touch position.

var realWorldPos = Camera.main.ScreenToWorldPoint(touch.position);

if(realWorldPos.x < maximumXSwipePosition && realWorldPos.x > minimumXSwipePosition)
{
    //do the stuff you want to do
}
//otherwise, don't do it.

Upvotes: 0

Related Questions