using UnityEngine; using UnityEngine.UI; public class ScrollRectAutoToggle : MonoBehaviour { ScrollRect scrollRect; // ScrollRect 참조 private void OnEnable() { AdjustScrollability(); } void AdjustScrollability() { if (scrollRect == null) scrollRect = GetComponent(); if (scrollRect == null || scrollRect.content == null) return; RectTransform viewport = scrollRect.viewport; // ScrollRect의 Viewport // Content의 크기가 Viewport보다 작거나 같으면 스크롤 불가능 bool canScrollHorizontally = scrollRect.content.rect.width > viewport.rect.width; bool canScrollVertically = scrollRect.content.rect.height > viewport.rect.height; scrollRect.horizontal = canScrollHorizontally; scrollRect.vertical = canScrollVertically; } }