Why when i slide my content its always stuck

157460-movie002.gif

here’s my code:

using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class swipe_control : MonoBehaviour
    {
        public GameObject scrollbar;
        float scroll_pos = 0;
        float[] pos;
        // Start is called before the first frame update
        void Start()
        {
            
        }
    
        // Update is called once per frame
        void Update()
        {
            pos = new float[transform.childCount];
            float distance = 1f / (pos.Length - 1f);
            for (int i = 0; i < pos.Length; i++){
                pos _= distance * i;_

}

if (Input.GetMouseButton(0))
{
scroll_pos = scrollbar.GetComponent ().value;
}
else
{
for(int i = 0; i < pos.Length; i++)
{
if(scroll_pos < pos + (distance / 2) && scroll_pos > pos - (distance / 2))
{
scrollbar.GetComponent ().value = Mathf.Lerp(scrollbar.GetComponent ().value, pos[1], 0.15f);
}
}
}
}
}

Look at the line of code, where you have your Mathf.Lerp method:

scrollbar.GetComponent<Scrollbar> ().value = Mathf.Lerp(scrollbar.GetComponent<Scrollbar> ().value, pos[1], 0.15f);

Replace it like that:

scrollbar.GetComponent<Scrollbar> ().value = Mathf.Lerp(scrollbar.GetComponent<Scrollbar> ().value, pos*, 0.15f);*