Exemplo n.º 1
0
    // used for treating mouse-clicks as touchs
    private void HandleTouch(int touchFingerId, Vector3 touchPosition, TouchPhase touchPhase)
    {
        // deltaTime in seconds -- not the way to handle, need time and position
        bool beginTouch = touchPhase.Equals(TouchPhase.Began);



        if (beginTouch)
        {
            Vector2 touchPosition2D = touchPosition;

            Debug.DrawRay(Vector3.zero, touchPosition, Color.blue, 1.0f);

            // have to check all hits to make sure bounding box isn't the only passed
            RaycastHit2D[] allRayHits = Physics2D.RaycastAll(touchPosition2D, new Vector3(0, 0, -10));


            // TODO: add enemy objects that shouldn't be hit and reduce points
            foreach (RaycastHit2D rayHit in allRayHits)
            {
                // need the tag check to avoid passing the bounding box
                if (rayHit && rayHit.transform.gameObject.tag.Equals("Ball"))
                {
                    // get the ball that was hit
                    GameObject ball = rayHit.transform.gameObject;


                    Splits.split(ball, touchPosition2D, ballsCreated);
                }
            }
        }
    }