Hey all, I’ve got the technical script working. Want to collab on how to solve a logic/design problem.
This is for an Android apk and deals with Input.Touch api.
Background:
First, one touch triggers a raycast that functions as OnMouseDown. Source: wiki.unity3d.com - OnMouseDown
Second, a 2 finger multi-touch (Input.touchCount > 1) I am using a camera-pan action.
Problem:
When you use two fingers, the first hit triggers the initial raycast. A two finger touch, on the millisec level, is two 1 finger touches.
Solution:
??? Any ideas? Maybe a very short check before the ray cast that a second finger doesn’t also hit. Not sure how to, but will open this thread up for ideas as I continue to work on it.
I had to deal with this in an android project and my solution was to not trigger anything when the user touches the screen, instead trigger it when he releases the finger. I can send you the file if you want to test it out. I’m not terribly satisfied with the solution but it’s still better than measuring micro seconds and having the user accidentally clicking when he wanted to pan the camera etc.
So, you’re suggesting using… touch.phase == Touch.Ended //Rather than Touch.Began
My only concern is this scenario: User does a two finger swipe, pan the camera and dont trigger the ray cast, and then lift both their fingers, and the raycast will trigger from wherever they pick up their finger.
I’ll test this later on my dev platform, but I think this might occur.
It has to be carefully planned. I had a boolean variable like “canClick” or something and if the finger count gets above 1 this would turn false thus ignoring attempts to click. This prevents two fingers camera control to register a click.
I’ll get you the file. Hang on.
Hope I didn’t cut anything important in my cleaning up.
#pragma strict
private var TwoFingerMode : boolean = false;
function Update () {
if(TwoFingerMode){
if(Input.touchCount==0){
TwoFingerMode = false;
}else{
//here goes all your two finger needs
}
}else{ //not two finger mode
if(Input.touchCount==1){
if(Input.GetTouch(0).phase == TouchPhase.Ended){
//do what has to be done when the user lifts his finger
}
}
if(Input.touchCount==2){
//change to two finger mode
//and do whatever needs to be done with two fingers
TwoFingerMode = true;
}
}
}
[Solved] That worked brilliantly! I don’t see a thanks button, but thank you sir.
One finger touch, and multi touch camera-pan. Perfect.