Unity/Unity 리서치

모바일 더블 터치(Mobile Double Touch) 구현

lipnus 2021. 6. 6. 15:57
반응형

 

간단히 구현해 보았음.

 

테스트 화면

 

Code

using UnityEngine.UI;
using UnityEngine;

public class TouchInput : MonoBehaviour
{
    public Text text1;
    public Text text2;
    public Text text3;
    public Text text4;

    private float lastTouchTime;
    private const float doubleTouchDelay = 0.5f;

    void Start() {
        lastTouchTime = Time.time;
    }

    void Update()
    {
        
        if(Input.touchCount == 1) {
            Touch touch = Input.GetTouch(0);

            switch (touch.phase)
            {
                case TouchPhase.Began:
                    
                    if(Time.time - lastTouchTime < doubleTouchDelay) // 더블터치 판정
                    {
                        text1.text = "TouchPhaes.Began (Double Touch)";
                        text4.text = "마지막입력: Double Touch"; 
                    }
                    else
                    {
                        text1.text = "TouchPhaes.Began";
                        text4.text = "마지막입력: 그냥터치";
                    } 
                    break;

                case TouchPhase.Moved:
                    text1.text = "TouchPhaes.Moved";
                    break;

                case TouchPhase.Ended:
                    text1.text = "TouchPhaes.Ended";
                    text2.text = $"Time: {Time.time}";
                    lastTouchTime = Time.time;
                    break;
            }
        }

    }
}

 

 

 

 

 

Unity - Scripting API: Touch.phase

The touch phase refers to the action the finger has taken on the most recent frame update. Since a touch is tracked over its "lifetime" by the device, the start and end of a touch and movements in between can be reported on the frames they occur. The phase

docs.unity3d.com

 

반응형

'Unity > Unity 리서치' 카테고리의 다른 글

Mobile Pinch Zoom  (0) 2021.06.09
Mouse DoubleClick  (0) 2021.06.08
Mobile에서 터치 드래그 구현  (0) 2021.06.06
에셋 번들 (Asset bundle) & 어드레서블(Addressables)  (0) 2021.06.05
[RTS Engine] Unit Attack 공격 딜레이  (0) 2021.06.04