반응형
- 코드 작성
using UnityEngine;
using UnityEngine.UI;
public class ScrollbarController : MonoBehaviour
{
public Scrollbar scrollbar;
public RectTransform contentTransform;
void Start()
{
scrollbar.onValueChanged.AddListener(OnScrollbarValueChanged);
}
void OnScrollbarValueChanged(float value)
{
float contentHeight = contentTransform.rect.height;
float viewportHeight = scrollbar.GetComponent<RectTransform>().rect.height;
float newYPos = (contentHeight - viewportHeight) * value;
contentTransform.anchoredPosition = new Vector2(contentTransform.anchoredPosition.x, newYPos);
}
}
반응형