겨울팥죽 여름빙수
private void ScrollMoveToTargetObject(Vector2 _targetPosition)
{
    scrollRect.verticalNormalizedPosition = 
        (_targetPosition.y - scrollRect.GetComponent<RectTransform>().rect.height*0.5f)
        /(scrollRect.content.rect.height - scrollRect.GetComponent<RectTransform>().rect.height);
}

 

 위 코드는 ScrollRect/Content내의 타겟 Object로 이동하는 코드이다. 새로 스크롤이고, 해당 타겟이 가운데로 오게끔한다.

공식은 다음과 같다.

 

  • verticalNormalizedPosition = (타겟의 위치 - ScrollRect 크기*0.5)/(Content 크기 - ScrollRect 크기)
    • 0이면 스크롤 가장 아래로, 1이면 가장 위로 이동한다.

 

 

profile

겨울팥죽 여름빙수

@여름빙수

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!