for (int i = 0; i < Input.touchCount; ++i) { var touch = Input.touches[i]; if (touch.phase == TouchPhase.Began) { if (!EventSystem.current.IsPointerOverGameObject(touch.fingerId)) { Debug.Log(touch.fingerId + ": タップ!"); } } }
// EventSystem.current.IsPointerOverGameObject(touch.fingerId) // がうまく動かないので、その代わり privatestatic List<RaycastResult> raycastResults = new List<RaycastResult>(); // リストを使いまわす publicstaticboolIsPointerOverUIObject(Vector2 screenPosition) { // Referencing this code for GraphicRaycaster https://gist.github.com/stramit/ead7ca1f432f3c0f181f // the ray cast appears to require only eventData.position. PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current); eventDataCurrentPosition.position = screenPosition;
EventSystem.current.RaycastAll(eventDataCurrentPosition, raycastResults); var over = raycastResults.Count > 0; raycastResults.Clear(); return over; }