Unity3D ScrollView scroll range
===

i'm trying to do a scrollView but i don't know how to determine the maximum range of the scroll, or better, the maximum scroll position.

This is what i was trying to do without positive results:

   

    void Update()
    {
      //get the amount of space that my text is taking
      textSize = gs.CalcHeight(new GUIContent(text), (screenWidth/2));
    
      if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(0).tapCount==1) 
      {
        var touch = Input.touches[0];
    
       //check if touch is within the scrollView area
       if(touch.position.x >= (screenWidth/2) && touch.position.x <= (screenWidth) && touch.position.y >= 0 && touch.position.y <= (screenHeight))
       {
         if(touch.phase == TouchPhase.Moved)
         {
           scrollPosition[1] += touch.deltaPosition.y;
           if(scrollPosition[1] < 0)
           {
               scrollPosition[1] = 0;
           }
    
           //I subtracted this cause i read that the scrollbars take 16px
           if(scrollPosition[1] > (textSize-scrollViewRect.yMax-16)) //scrollViewRect is a Rect with the size of my scrollView
           {
              scrollPosition[1] = textSize-scrollViewRect.yMax-16;
           }
         }
       }
      }
    }
    
    void OnGUI()
    {
     screenWidth = camera.pixelWidth;
     screenHeight = camera.pixelHeight;
     GUILayout.BeginArea(new Rect(screenWidth/2, 0, screenWidth/2, screenHeight));
    
     GUILayout.BeginScrollView(scrollPosition/*, GUILayout.Width (screenWidth/2), GUILayout.Height (screenHeight/2)*/, "box");
    
     GUILayout.Label (new GUIContent(texto), gs);
    
    
     // End the scrollview
     GUILayout.EndScrollView ();
     scrollViewRect = GUILayoutUtility.GetLastRect();
     GUILayout.EndArea();
    }

This was done assuming that the scrollView is on the right half of the screen.

Can you guys help me out on this?

Thanks in advance.