private bool bInTouch = false;
private float ClickAfter = 0.0f;
GameObject m_curClickBox;
private Vector3 mousePosLast = Vector3.zero;
private bool Dragged = false;

private bool bTemporarySelect = false;
public void Update()
{

//有按钮一直按下,在PC端是鼠标左键一直按下。。移动端可代表一直在滑动
if (Input.GetMouseButton(0))
{
//点击到UI上
if (Application.isMobilePlatform && Input.touchCount > 0)
{
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
return;
}
else if (EventSystem.current.IsPointerOverGameObject())
{
return;
}

//未点在UI上,
//之前没按下
if (bInTouch == false)
{

bInTouch = true;//当前点击了一个建筑
ClickAfter = 0.0f;
mousePosLast = Input.mousePosition;
bTemporarySelect = false;
Dragged = false;
}
else //之前按下了
{
//与上次点击距离超过阈值为滑动
if (Vector3.Distance(Input.mousePosition, mousePosLast) > 0.01f)
{
if (!Dragged)
{
Dragged = true;
}
}
else //按下,且一直长按超过阈值 为点击
{
if (!Dragged)
{
ClickAfter += Time.deltaTime;
if (!bTemporarySelect && (ClickAfter > 0.5f))
{
bTemporarySelect = true;
//Debug.Log ("Update2 buildingSelected:"+((buildingSelected != null) ? buildingSelected.name : "none"));
//按下到松手且不移动,判定为点击状态
PickOneBox();
}
}
}
}
}
else //触摸抬起或者按下,实际处理抬起事件
{
if (bInTouch)
{
bInTouch = false;

if (Dragged)
{
//在持续期间判断为拖动,执行拖动逻辑
}
else//执行点击
{
if (bTemporarySelect) //长按
{
}
else
{
PickOneBox();
}
}
}
}
}
void PickOneBox()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.gameObject.tag == "HtBox")
{
hit.collider.gameObject.GetComponent<BoxCtrl>().OnPick();

}
}
}

unity3d:物体点击与拖动互不影响_移动端