Gday, I’m not sure if it was a Unity update, but my touch phases have gone weird.
The problem is, when I press the button, and then press somewhere on the screen,(anywhere)
with another finger, it cancels the touch event?
It never happened before…
Thanks in advance, Tim.
var tap1Zone : GUITexture;
var pressing : boolean = false;
function Update(){
for (var touch : Touch in Input.touches){
if (touch.phase == TouchPhase.Began && tap1Zone.HitTest (touch.position)) {
pressing = true;
}
else if (touch.phase == TouchPhase.Ended && tap2Zone.HitTest) {
pressing2 = false;
}
}
}
First, enabled multitouch, and second, little correct your script:
var tap1Zone: GUITexture;
var tap2Zone: GUITexture;
var pressing: boolean = false;
var pressing2: boolean = false;
var finId1: int = -1; //id finger for cancel touch event
var finId2: int = -1;
function Start() {
Input.multiTouchEnabled = true; //enabled Multitouch
}
function Update() {
for (var touch : Touch in Input.touches) {
if (touch.phase == TouchPhase.Began && tap1Zone.HitTest (touch.position) && finId1 == -1) {
pressing = true;
finId1 = touch.fingerId; //store Id finger
}
if (touch.phase == TouchPhase.Began && tap2Zone.HitTest (touch.position) && finId2 == -1) {
pressing2 = true;
finId2 = touch.fingerId;
}
if (touch.phase == TouchPhase.Ended) { //correct code
if(touch.fingerId == finId1) { //check id finger for end touch
pressing = false;
finId1 = -1;
} else if(touch.fingerId == finId2) {
pressing2 = false;
finId2 = -1;
}
}
}
}
I hope that it willhelp you.