구현하려고 하는건 스마트폰 터치로 터치 슬라이드를 구현하려고 하는데요
y축으로 증가하는것만 알면되거든요 위로 슬라이드 할수있게끔요
일단 기본적으로는 왼쪽이랑 오른쪽 슬라이드가 가능하게 해두었는데요
슬라이드가 일정수치만큼 되었는지 체크를 하는것까지는 했는데
왼쪽오른쪽도 구분을 하게 해두었는데
한쪽씩은 가능한데 양쪽다 해보려고 하니까 하나씩밖에 안되는거에요..
(로그가 동시에 안뜨고 하나씩만 뜨더라구요..)
정리를 하면 위쪽으로 슬라이드하는 기능을 만드는데 이게 왼쪽 오른쪽으로 구분해서 슬라이드를 하게끔했는데
이게 양쪽으로도 슬라이드가 되게 하고싶은데 한쪽씩밖에 안되서 질문드립니다.
코드 전문 올립니다.
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 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class slidetouch : MonoBehaviour { public float startpos; public float currentpos; Touch temptouch; public Vector3 touchedPos; public float screenhalfsize; public int touchvec; void Start() { screenhalfsize = Screen.width * 0.5f; } void Update () { if (Input.touchCount > 0) { for (int i = 0; i < Input.touchCount; i++) { temptouch = Input.GetTouch(i); if (temptouch.phase == TouchPhase.Began) { touchedPos = temptouch.position; touchvec = touchvector(); startpos = touchedPos.y; } else if(temptouch.phase == TouchPhase.Moved) { currentpos = Input.GetTouch(i).position.y; float resultpos = currentpos - startpos; if (resultpos > 200 && touchvec == 0) { Debug.Log("left good"); } else if (resultpos < 200 && touchvec == 0) { //Debug.Log("left bad"); } if (resultpos > 200 && touchvec == 1) { Debug.Log("right good"); } else if (resultpos < 200 && touchvec == 1) { //Debug.Log("right bad"); } } else if(temptouch.phase == TouchPhase.Ended) { startpos = 0; currentpos = 0; } } } } int touchvector() //왼쪽이면0 오른쪽이면 1을 반환 { int vec = 0; if (touchedPos.x > screenhalfsize) { vec = 1; //Debug.Log("Right"); } else { vec = 0; // Debug.Log("Left"); } return vec; } } | cs |
제가 자세히는 못봐서 틀릴수 있는데.. 일단 startpos, currentpos 가 한벌 밖에 없네요. for (int i = 0; i < Input.touchCount; i++) 이렇게 for문 돌아서 손가락 2개가 동시에 처리돼야 하는데 startpos, currentpos 가 1벌 뿐이니까 0번 터치가 기록한 값을 1번 터치가 덮어쓰고 그래서 1개만 인식되는 문제가 아닐까여