상세 컨텐츠

본문 제목

유니티 모바일 터치

유니티/기능

by MJ_119 2024. 7. 6. 03:27

본문

참고 유튜브 : https://www.youtube.com/watch?v=oQ1toHKSGIQ

 

- 줌인 줌아웃.

- 뒤로가기 버튼, 홈 버튼, 메뉴 버튼

 

 

간단한 예제

using UnityEngine;

public class TouchInput : MonoBehaviour
{
    void Update()
    {
        // 현재 터치된 손가락 수를 가져옵니다.
        int touchCount = Input.touchCount;

        // 터치된 손가락이 하나 이상일 경우 처리합니다.
        if (touchCount > 0)
        {
            for (int i = 0; i < touchCount; i++)
            {
                Touch touch = Input.GetTouch(i);

                // 터치의 위치를 가져옵니다.
                Vector2 touchPosition = touch.position;

                // 터치의 상태를 확인합니다.
                switch (touch.phase)
                {
                    case TouchPhase.Began:
                        Debug.Log("터치 시작: " + touchPosition);
                        break;
                    case TouchPhase.Moved:
                        Debug.Log("터치 이동: " + touchPosition);
                        break;
                    case TouchPhase.Stationary:
                        Debug.Log("터치 유지: " + touchPosition);
                        break;
                    case TouchPhase.Ended:
                        Debug.Log("터치 종료: " + touchPosition);
                        break;
                    case TouchPhase.Canceled:
                        Debug.Log("터치 취소: " + touchPosition);
                        break;
                }
            }
        }
    }
}

관련글 더보기