Flick scroll

Can anyone tell me why flick scroll in this script not working ?

using UnityEngine;
using System.Collections;

public class FlickList : MonoBehaviour
{
	public string[] list;
	public Rect rect = new Rect (10, 10, 100, 100);
	public Rect buttonRect = new Rect (0, 0, 100, 30);
	public float flickDeltaPosition = 20;

	public Vector2 scrollPosition = Vector2.zero;
	public float scrollSpeed = 0, scrollDeceleration = 0.2f;
	public float maxPosition;
	Rect virtualView;

	void Start ()
	{
		virtualView = new Rect (0, 0, 80, list.Length * buttonRect.height);
		maxPosition = virtualView.height - rect.height;
	}

	void Update ()
	{
		for (int i = 0; i < iPhoneInput.touchCount; i++) {
			iPhoneTouch touch = iPhoneInput.GetTouch (i);
			if (touch.phase == iPhoneTouchPhase.Moved) {
				if (Mathf.Abs (touch.deltaPosition.y) > flickDeltaPosition) {
					scrollSpeed = touch.deltaPosition.y;
				}
			}
		}
		if (scrollSpeed > 0) {
			scrollPosition += new Vector2 (0, scrollSpeed);
			scrollSpeed -= scrollDeceleration;
		}
		if (scrollSpeed < 0) {
			scrollPosition -= new Vector2 (0, scrollSpeed);
			scrollSpeed += scrollDeceleration;
		}
		if (scrollPosition.y > maxPosition) {
			scrollPosition.y = maxPosition;
			scrollSpeed = 0;
			// should be a nice apple-y bounce
		}
		if (scrollPosition.y < 0) {
			scrollPosition.y = 0;
			scrollSpeed = 0;
			// should be a nice apple-y bounce
		}
	}

	public string text;

	void OnGUI ()
	{
		scrollPosition = GUI.BeginScrollView (rect, scrollPosition, virtualView);
		for (int i = 0; i < list.Length; i++) {
			Rect thisButtonRect = new Rect (10, i * buttonRect.height, buttonRect.width, buttonRect.height);
			if (GUI.Button (thisButtonRect, list[i])) {
				
			}
		}
		GUI.EndScrollView ();
		
		iPhoneKeyboard keyboard;
		if (GUI.Button (new Rect (rect.height + 10, 10, 200, 32), text))
			keyboard = iPhoneKeyboard.Open (text, iPhoneKeyboardType.ASCIICapable);
		
		if (keyboard != null)
			text = keyboard.text;
	}
}

In what way is it not working? Can you describe what it actually is doing?

Your > 0 statement needed to change to allow for scrolling up. There also needed to be another check inside of these statements based on a threshold value. Otherwise the scrollbar would just “creep” along.

You need to make the following changes to your code:

      if (scrollSpeed > 0) {
         scrollPosition += new Vector2 (0, -scrollSpeed);
         scrollSpeed -= scrollDeceleration;
        
         if(scrollSpeed < 1) {
         	scrollSpeed = 0;
         }
      }
      if (scrollSpeed < 0) {
         scrollPosition -= new Vector2 (0, scrollSpeed);
         scrollSpeed += scrollDeceleration;
  
         if(scrollSpeed > -1) {
         	scrollSpeed = 0;
         }
      }

If you want to add glide and bounce, look into lerping your velocity to zero once the touch has ended, and lerping a force in the opposite direction once the scroll vector goes beyond your min and max values.