Unity - Scroll view gets stuck while scrolling too fast

Viewed 88

I am trying to make a parallax scroll-and-snap scroll view on a iOS iPhone game(a duplicate of the game Arknights) in unity. But sometimes(not always) when I swipe too fast, the scroll view gets stuck between 2 elements of the scroll view. In the video which shows this error, I started swiping very fast until the error occurs, then I swiped slowly, one by one, to see the error clearly. Any ideas on how to solve this? My script that are relevant are as follows(please tell me if more is needed~):

Video showing the error:https://youtu.be/tSrRG3kdpnA

 void LerpTargetPos()
    {
        StopAllCoroutines();
        StartCoroutine(LerpTargetPosCoroutine());
    }
    IEnumerator LerpTargetPosCoroutine()
    {
        if (scrollRect.horizontalNormalizedPosition != targetPos)
        {
            scrollRect.horizontalNormalizedPosition = Mathf.Lerp(scrollRect.horizontalNormalizedPosition, targetPos, lerpSpeed * Time.deltaTime);
        }
        if (Mathf.Abs(scrollRect.horizontalNormalizedPosition - targetPos) <= 0.0005f)
        {
            scrollRect.horizontalNormalizedPosition = targetPos;
        }
        yield return null;
    }
if (canLerp)
  {
      LerpTargetPos();
  }
1 Answers

Ok – turns out I put the LerpTargetPos method in the LateUpdate method, instead of Update; after I put it in Update, everything seems to work fine.

Related