- Home /
Two touches in same time?
Hi, I try detect two touches like: first touche right walk together with a second touch in a collider button shoot. this two separate touches start an animation. My code is this, what is wrong?.
private int finId1 = -1; //id finger for cancel touch event
private int finId2 = -1;
void Start() {
Input.multiTouchEnabled = true; //enabled Multitouch
}
void Update() {
//First check count of touch
if (Input.touchCount > 0) {
foreach (Touch touch in Input.touches) {
Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch (touch.fingerId).position);
RaycastHit hit;
if (Input.GetTouch (touch.fingerId).phase == TouchPhase.Began) {
if (collider.Raycast (ray, out hit, 1000.0f)) {
if (collider.gameObject.name == "Seta_right") {
//Do something
finId1 = touch.fingerId; //store Id finger
GUI.Label(new Rect(10,10,120,100), "finId1: "+finId1);
}
}
}
if (Input.GetTouch (touch.fingerId).phase == TouchPhase.Began) {
if (collider.Raycast (ray, out hit, 1000.0f)) {
if (collider.gameObject.name == "btn_quadrado") {
//Do something
finId2 = touch.fingerId;
GUI.Label(new Rect(10,30,120,100), "finId1: "+finId2);
}
}
}
if (touch.phase == TouchPhase.Ended) { //correct end of touch
if(touch.fingerId == finId1) { //check id finger for end touch
finId1 = -1;
} else if(touch.fingerId == finId2) {
finId2 = -1;
}
}
}
}
}
void OnGUI(){
if ((finId1 == 0) && (finId2 == 0)) {
GUI.Label(new Rect(10,50,120,100), "OK");
}
}
Comment
Your answer
Follow this Question
Related Questions
One more question about touches 1 Answer
Separate functions for separate touches 1 Answer
Use touch to spawn a prefab 1 Answer
Check whether touch is held 0 Answers
Swipe Control Issue.. Need help 1 Answer