Unity/Unity 리서치

Mouse DoubleClick

lipnus 2021. 6. 8. 21:55
반응형
using UnityEngine;

public class MouseDoubleClick : MonoBehaviour
{
    public float m_DoubleClickSecond = 0.25f;
    private bool m_IsOneClick = false;
    private double m_Timer = 0;

    private void Update()
    {
        if (m_IsOneClick && ((Time.time - m_Timer) > m_DoubleClickSecond))
        {
            Debug.Log("One Click");
            m_IsOneClick = false;
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (!m_IsOneClick)
            {
                m_Timer = Time.time;
                m_IsOneClick = true;
            }

            else if (m_IsOneClick && ((Time.time - m_Timer) < m_DoubleClickSecond))
            {
                Debug.Log("Double Click");
                m_IsOneClick = false;
            }
        }
    }
}
반응형