public void GetClickType()
{
if(Input.GetMouseButtonDown(0))
{
if(isGetBeginPos)
{
beginPosition = Input.mousePosition;
isGetBeginPos = false;
}
if(isCheckCollider)
{
//检测碰撞体 isCheckCollider = false;
}
} if(Input.GetMouseButton(0))
{
timer += Time.deltaTime;
curPosition = Input.mousePosition;
if(Mathf.Abs(curPosition.x - beginPosition.x)<0.05f && Mathf.Abs(curPosition.y - beginPosition.y<0.05f)
&& curPosition.z - beginPosition.z<0.05f)
{
//以1S为点击和长按的判定条件
if(timer > 1)
{
isLongPress = true;
}
else
{
isSingleClick = true;
}
}
else
{
isPadding = true;
}
}
if(Input.GetMouseButtonUp(0))
{
if(isSingleClick){
clickType = ClickType.SingleType;
isSingleClick=false;
}else if(isLongPress)
{
clickType = ClickType.LongPress;
isLongPress = false;
}else if(isPadding)
{
clickType = ClickType.Padding;
isPadding = false;
}
}
}
总体来说是用布尔值和时间来控制的,多久时间算长按是根据具体需求走的