Two-finger scroll gesture recognizing on iphone

I want to change camera’s pitch angle when two-finger scroll up or down like the Google Map.
How can i recognize the two-finger scroll gesture?

PS. My try

        Vector2 scroll0 = Input.GetTouch(0).deltaPosition / Input.GetTouch(0).deltaPosition.magnitude;
			Vector2 scroll1 = Input.GetTouch(1).deltaPosition / Input.GetTouch(1).deltaPosition.magnitude;
			if (scroll1 == scroll0)
				rotationY = Input.GetTouch(0).deltaPosition.magnitude;
				if (Input.GetTouch(0).deltaPosition.y < 0)							// scroll down
					rotationY = -rotationY;
				rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
				worldCamera.transform.Rotate(rotationY, 0, 0);

Ok, so the first thing to do is to create a function we can use to detect when two touches are first placed down.

Unity.Touch types have a phase member which let’s you know when a touch first begins, among other gestures. However, since we are doing two Touches, that can be tricky because if we were to just use the condition, touch1.phase == TouchPhase.Began && touch2.phase == TouchPhase.Began, it will only count if the user presses both fingers down immediately at the same time. Most people expect more leniency, so we also need to account for when the user already has placed one finger down and the other starts, and also for if one finger is moving on the touch pad while the the second is starting.

static bool IsBegun(Touch touch1, Touch touch2)
    return (touch1.phase == TouchPhase.Began && touch2.phase == TouchPhase.Began) ||
            (touch1.phase == TouchPhase.Stationary && touch2.phase == TouchPhase.Began) ||
            (touch1.phase == TouchPhase.Moved && touch2.phase == TouchPhase.Began);

Secondly, you want a function that can get the midpoint between the two touch points. For this, we can use the Lerp function:

	Vector2 GetMidpoint(Touch touch1, Touch touch2)
		return Vector2.Lerp (touch1.position, touch2.position, 0.5f);

We want the midpoint between the two touch points, because that will give us a consistent place to track and treat as if the two touches are one touch.

Next, we create a variable that represents the distance we want the max distance from the starting point.:

//the max distance. change this number to your liking.
const float MAX_DIFFERENCE = 10f;

Also, we create a class variable for the starting point.

// for saving the initial point.
Vector2 startPoint =;

Lastly, this function will take the two touches and gives us a value between -1 and 1. We do this by saving the point when we detect the beginning of a two touch gesture, then by performing vector subtraction on the starting point and current point to get the difference, then taking the value of axis we wish to treat as our range.

float GetInputRange()
	// do not do anything until there are at least two points.
	if(Input.touchCount < 2)
		return 0;
	// capture the touch points
	Touch touch1 = Input.GetTouch(0);
	Touch touch2 = Input.GetTouch(1);
	// gets the midpoint between the two touches
	var midpoint = GetMidpoint(touch1, touch2);
	// if its just started, save the first point.
	if(IsBegun(touch1, touch2))
			startPoint = midpoint;
	// get the difference between the two points.
	var difference = startPoint - midpoint;
	// now, get either x or y here. change this line to use x or y to your liking. 
    // makes it so that if x = MAX_DIFFERENCE, then result = 1
	var result = difference.x / MAX_DIFFERENCE;
	// optional: make sure it never gets bigger than 1 or smaller than -1
	result = Mathf.Clamp(result, -1.0f, 1.0f);
	return result;

And this function just shows you what the value is on the screen. just for debugging.

// show us the value on screen
void OnGUI()
	GUI.Label(new Rect(100, 100, 200, 200), GetInputRange().ToString());

The result is a value that treats the starting point as neutral and as you move farther away from the neutral point, the strength (0 to 1) and direction(positive or negative) of the pull can be calculated to determine the strength and direction of your camera pitch.