반응형
- 코드 작성
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);
}
}
반응형
'개발 > Unity' 카테고리의 다른 글
유니티 Unity C# 메모리 누수를 방지하는 방법 Memory (0) | 2023.12.05 |
---|---|
유니티 C# 기본 문법 정리 - 변수, 조건문, 반복문, 배열, 함수, 클래스 등등 (0) | 2023.10.18 |
java.io.IOException: Can't read [C:\Users\shahp\.gradle\caches\transforms-2\files- 에러 대응법 (0) | 2023.08.24 |
Unity iOS Xcode 빌드시 Info.plist 자동 수정 간단 구현 (0) | 2023.08.19 |
유니티 C# 네임스페이스 간단 사용법 Unity namespace (0) | 2023.04.30 |
유니티 쉐이더 Shader 간단 사용법 (0) | 2023.03.31 |
유니티 에디터 단축키 간단 사용법 Unity Editor (0) | 2023.02.17 |
유니티 생명 주기 Life Cycle 간단 설명 (0) | 2022.08.17 |
댓글