using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Scrollable : MonoBehaviour { public int ignoreElements = 0; public bool horizontal = false; void Start() { Reload(); } public void Reload() { var size = 0f; if (horizontal) { size = (transform.childCount - ignoreElements) * ((transform.GetChild(0).GetComponent().sizeDelta.x * transform.GetChild(0).localScale.x) + GetComponent().spacing); } else { size = (transform.childCount - ignoreElements) * (transform.GetChild(0).GetComponent().sizeDelta.y + GetComponent().spacing); } if (horizontal) { GetComponent().offsetMin = Vector2.zero; }else { GetComponent().offsetMax = Vector2.zero; } if (horizontal) { GetComponent().offsetMax = new Vector2(-(transform.parent.GetComponent().sizeDelta.x > size ? 0 : -size + transform.parent.GetComponent().sizeDelta.x + GetComponent().spacing), GetComponent().offsetMax.y); } else { GetComponent().offsetMin = new Vector2(GetComponent().offsetMin.x, transform.parent.GetComponent().sizeDelta.y > size ? 0 : -size + transform.parent.GetComponent().sizeDelta.y + GetComponent().spacing); } } void Update() {} }