2016. 4. 29. 14:31
https://blog.naver.com/nagne2011/220696716257
void Update ()
{
if (Input.touchCount > 0)
{
if (Input.GetTouch (0).phase == TouchPhase.Began)
{//초기 터치 지점
zeroPoint = Input.GetTouch(0).position;
}
else if (Input.GetTouch (0).phase == TouchPhase.Moved)
{//현재 터치 지점
currentPoint = Input.GetTouch (0).position;
//변화량 저장
float deltaX = currentPoint.x - zeroPoint.x;
float deltaY = currentPoint.y - zeroPoint.y;
if (Mathf.Abs (deltaX) > Mathf.Abs (deltaY))
{//x축으로 이동상태
if (deltaX > 0)
{//우측으로 당김
Debug.Log("우측으로 당김");
}
else if (deltaX < 0)
{//좌측으로 당김
Debug.Log("좌측으로 당김");
}
}
else if (Mathf.Abs (deltaX) < Mathf.Abs (deltaY))
{//y축으로 이동상태
if (deltaY > 0)
{//위쪽으로 당김
Debug.Log("위쪽으로 당김");
}
else if (deltaY < 0)
{//아래쪽으로 당김
Debug.Log("아래쪽으로 당김");
}
}
}
}
728x90
'유니티' 카테고리의 다른 글
유니티 파일/폴더 생성, 삭제, 확인 (0) | 2022.02.14 |
---|---|
유니티 XML 저장/불러오기 (0) | 2022.02.14 |
유니티 버튼만들기 (0) | 2022.02.13 |
유니티 스카이맵 (0) | 2022.02.13 |
유니티 material (0) | 2022.02.13 |