コード例 #1
0
        private void HandleInputMobile()
        {
            if (Input.touchCount == 1)
            {
                Touch touch = Input.GetTouch(0);
                TouchPosition = (Vector2)Camera.main.ScreenToWorldPoint(touch.position);
                RaycastHit2D raycastHit = Physics2D.Raycast(TouchPosition, Vector3.forward, Mathf.Infinity);

                if (elementClicked != null)
                {
                    switch (touch.phase)
                    {
                    case TouchPhase.Moved:
                        elementClicked.TouchDrag();
                        break;

                    case TouchPhase.Ended:
                        elementClicked.TouchUp();
                        elementClicked = null;
                        break;
                    }
                }
                else if (touch.phase == TouchPhase.Began)
                {
                    if (raycastHit)
                    {
                        elementClicked = raycastHit.collider.GetComponent <ITouchable>();
                    }
                }
            }
            else
            {
                ClearElementClicked();
            }
        }