I’m newbie in Unity, C# and not so good in English so please be lenient.
I’m trying to do infinity horizontal scroll view using UI, it is important for me to have inertia movement when dragging released. So I have scrollview gameobject with Scroll Rect component and child content with horizontal layout group and content size fitter components on it. I put anchors in four corners of this two GO. on enable with my script on scroll view gameobject I put child objects with image component on content to fill all horizontal space on it. then in update i check if content anchoredPosition.x is greater then 0 then i put last content element in hierarchy in the beginning, so it moves from right side of content to left and then i move content left on element width, also i do with right side, here is script
void Update()
{
if (_contentRectTransform.anchoredPosition.x > 0.0f)
{
content.transform.GetChild(content.transform.childCount-1).SetSiblingIndex(0);
_contentRectTransform.anchoredPosition = new Vector2 (_contentRectTransform.anchoredPosition.x-SpriteWidth-4,_contentRectTransform.anchoredPosition.y)
}
if (Mathf.Abs(_contentRectTransform.anchoredPosition.x) > _contentRectTransform.sizeDelta.x)
{
content.transform.GetChild(0).SetSiblingIndex(content.transform.childCount-1);
_contentRectTransform.anchoredPosition = new Vector2 (_contentRectTransform.anchoredPosition.x+SpriteWidth+4,_contentRectTransform.anchoredPosition.y);
}
so everything goes well if i release dragging before content anchoredposition pass through conditions. and if it reaches conditions inertially everything good, but if i continue dragging i have strange behavior, conditions in update reached every frame, looks like content anchoredPosition have wrong values because of automation on content or scroll rect.
I put video of this for better understanding of my problem.
So maybe someone knows how to prevent this.