// Update is called once per frame void Update() { foreach (Touch touch in Input.touches) { TouchPhase phase = touch.phase; if (phase == TouchPhase.Began) { //Keep track of the first touch if (touchStartPositions.Count == 0) { primaryTouchFingerId = touch.fingerId; } //Add touch to dictionary (regardless) touchStartPositions.Add(touch.fingerId, touch.position); } else { //Interpret touch as "drag" (first touch only) if (primaryTouchFingerId == touch.fingerId) { Vector3 displacement = GetDisplacement(touch); if (displacement.magnitude >= minimumDragSize) { SetNextMove(displacement.normalized); } } //Remove touch when finished if (phase == TouchPhase.Ended || phase == TouchPhase.Canceled) { //Interpret touches as "taps" or "drags" Vector3 displacement = GetDisplacement(touch); if (displacement.magnitude >= minimumDragSize) { SetNextMove(displacement.normalized); } else if (displacement.magnitude <= minimumDragSize) { Vector3 touchPositionInWorld = Camera.main.ScreenToWorldPoint(touchStartPositions[touch.fingerId]); RaycastHit2D hitInformation = Physics2D.Raycast(touchPositionInWorld, Camera.main.transform.forward); carrier.DoThrow((Vector2)touchPositionInWorld); if (hitInformation.collider != null) { GameObject touchedObject = hitInformation.transform.gameObject; carrier.DoCarry(touchedObject); } } //Free up the first touch variable if (primaryTouchFingerId == touch.fingerId) { primaryTouchFingerId = -1; } //Remove touch from dictionary touchStartPositions.Remove(touch.fingerId); } } } }
protected void HandleThrowAtPoint(Vector3 position) { if (!handleThrows) { return; } carrier.DoThrow((Vector2)position); }