判断是否点击,看前两个if(pausePanel.activeInHierarchy==false 判断物体显示状态 这个过滤掉)
#if UNITY_ANDROID || UNITY_IPHONE
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began&& pausePanel.activeInHierarchy==false)
{
if (!IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
if (transform.position.x >= 0)
{
sRenderer.flipX = false;
bCollider2D.offset = new Vector2(-bCollider2D.offset.x, bCollider2D.offset.y);
}
else
{
sRenderer.flipX = true;
bCollider2D.offset = new Vector2(-bCollider2D.offset.x, bCollider2D.offset.y);
}
aSource.PlayOneShot(side);
transform.position = new Vector2(-transform.position.x, transform.position.y);
}
}
#endif
IsPointerOverGameObject方法
bool IsPointerOverGameObject(int fingerId)
{
EventSystem eventSystem = EventSystem.current;
return (eventSystem.IsPointerOverGameObject(fingerId)
&& eventSystem.currentSelectedGameObject != null);
}