101 2Dカメラのピンチインアウト処理

// ピンチインアウト用.
private float pinchLength = 0.0f;
 
private void PinchInOut()
{
    if (Input.touchCount >= 2)
    {
        Touch touch0 = Input.GetTouch(0);
        Touch touch1 = Input.GetTouch(1);
 
        // 2点タッチ開始時の距離を記憶.
        if (touch1.phase == TouchPhase.Began)
        {
            pinchLength = Vector2.Distance(touch0.position, touch1.position);
        }
        // ピンチインアウト.
        else if (touch0.phase == TouchPhase.Moved && touch1.phase == TouchPhase.Moved)
        {
            float length = Vector2.Distance(touch0.position, touch1.position);
            m_Camera.orthographicSize += ((pinchLength - length) / 2) * 0.004f;
 
            float fMinSize = 1.0f;
            float fMaxSize = 3.0f;
            m_Camera.orthographicSize = Mathf.Clamp(m_Camera.orthographicSize, fMinSize, fMaxSize);
 
            pinchLength = length;
            }
        }
    }
}