제가 만들고자하는게 스마트폰 화면을 반으로 나눠서 왼쪽과 오른쪽구간을 나눠놓고

왼쪽터치후 위로 스와이프를 하면 left good 이라는 로그가 뜨고 반대로 오른쪽터치후 위로 스와이프를 하면 right good 이라는 로그가 뜨고

왼쪽과 오른쪽을 동시에 터치하고 위로 스와이프를하면 two touch slide good 이라는 로그가 뜨게 해놨는데요.

기본적으로 터치 시작부분에서 시작지점을 체크해놓고

터치를 때는순간 터치를 때는순간의 위치값에서 처음 위치를 빼버려서 얼마나 스와이프를 했는지로 성공과 실패를 판단하고 있거든요

그런데 이게 터치를 시작할때는 상관이없는데 터치를땔때 판단을 하다보니까

여기서 생각지도 못한일이 일어나더라구요..

왼쪽 스와이프..정상..오른쪽 스와이프..정상.. 양쪽 스와이프..정상..인듯 보였지만 왼쪽이나 오른쪽스와이프가 같이 일어나버리더라구요..

특이사항이라면 터치를때는순간 한손가락만떼어 내어도 twotouch slide good 이라는 로그가 뜨더라구요..두번째 손가락을 떼어냈을때는 해당방향의 스와이프가 일어나구요..

코드 전문인데 최대한 코드는 줄여봤는데 input클래스를 이용하다보니까 줄이는게 쉽지는 않네요..ㅠㅠ


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class slidetouch : MonoBehaviour
{
    public float startpos1;
    public float startpos2;
    public float currentpos1;
    public float currentpos2;
    float resultpos1;
    float resultpos2;
    Touch temptouch;
    public Vector3 touchedPos = new Vector3(000);
    public float screenhalfsize; // 화면의 절반위치를 담는다.
    public int touchvec;
 
 
    void Start()
    {
        screenhalfsize = Screen.width * 0.5f;// 화면 절반위치를 저장
    }
 
    void Update()
    {
        touch_command();
    }
 
    void touch_command()
    {
        if (Input.touchCount > 0)
        {
            for (int i = 0; i < Input.touchCount; i++)
            {
                temptouch = Input.GetTouch(i);
                if (temptouch.phase == TouchPhase.Began)
                {
                    touchedPos = temptouch.position;
                    if (Input.touches.Length == 1) // 터치시 손가락의 갯수파악 1개면..
                    {
                        touchvec = touchvector(); // 왼쪽인지 오른쪽인지 판단함
                        startpos1 = Input.touches[0].position.y; //최초 터치위치 저장
                    }
                    else if (Input.touches.Length == 2) // 손가락 갯수가 2개면
                    {
                        startpos1 = Input.touches[0].position.y; //터치위치 저장1
                        startpos2 = Input.touches[1].position.y; //터치위치 저장2
                    }
                }
 
                else if (temptouch.phase == TouchPhase.Ended) // 터치를 떼는순간 판단
                {
                    if (Input.touches.Length == 1) // 떼는손가락이 1개면..
                    {
                        currentpos1 = Input.touches[0].position.y; //손가락 떼는 최종위치 저장
                        resultpos1 = currentpos1 - startpos1; //최종위치와 시작위치의 거리를 파악하기위함
 
                        if (touchvec == 0) // 왼쪽터치시
                        {
                            if (resultpos1 > 200) //원하는 거리만큼 스와이프를 했으면..
                            {
                                Debug.Log("left good");
                            }
 
                            else if (resultpos1 < 200) // 원하는 거리만큼 안나오면 실패..
                            {
                                Debug.Log("left bad");
                            }
                        }
 
                        else if (touchvec == 1) // 오른쪽 터치시
                        {
                            if (resultpos1 > 200)
                            {
                                Debug.Log("right good");
                            }
 
                            else if (resultpos1 < 200 && touchvec == 1)
                            {
                                //Debug.Log("right bad");
                            }
                        }
                    }
                    else if (Input.touches.Length == 2) // 두손가락을 떼었다면..
                    {
                        currentpos1 = Input.touches[0].position.y;
                        currentpos2 = Input.touches[1].position.y;
                        resultpos1 = currentpos1 - startpos1;
                        resultpos2 = currentpos2 - startpos2;
 
                        if (resultpos1 > 200 && resultpos2 > 200)
                        {
                            Debug.Log("two touch slide good");
                        }
 
                        else if (resultpos1 < 200 && resultpos2 < 200)
                        {
                            //Debug.Log("two touch slide bad");
                        }
                        startpos1 = 0; // 초기화..
                        currentpos1 = 0;
                        startpos2 = 0;
                        currentpos2 = 0;
                    }
                }
            }
        }
    }
 
    int touchvector() // 왼쪽인지 오른쪽인지 판단후 왼쪽은 0 오른쪽은 1을 반환
    {
        int vec = 0;
 
        if (touchedPos.x > screenhalfsize)
        {
            vec = 1;
        }
        else
        {
            vec = 0;
        }
        return vec;
    }
}
 
 
 
cs

전체코드는 그렇게 복잡하지는 않은데 어느부분이 이상인건지 일주일째 잡고있는데 도무지 답이 안나오네요..
여기 고수님들이 많다는 소문을듣고 여기라면 혹시 도움을 받을수 있을까해서 질문올리게 되었습니다.