using System.Collections; using System.Collections.Generic; using UnityEngine; public class TextScrollView : MonoBehaviour { [SerializeField] private float m_MaxHeight = 245; [SerializeField] private float m_HeightSpeed = 10; private bool isScroll; private float m_NowHeight = 0; private float m_MaxScrollHeight = 0; private void OnEnable() { isScroll = false; m_NowHeight = 0; SetHeight(); StopCoroutine("DeleyJudgeHeight"); StartCoroutine("DeleyJudgeHeight"); } private IEnumerator DeleyJudgeHeight() { yield return new WaitForSeconds(1); Vector2 size = GetComponent().sizeDelta; m_MaxScrollHeight = (size.y - m_MaxHeight); if (size.y >= m_MaxHeight) { isScroll = true; } } // Update is called once per frame void Update() { if(isScroll) { m_NowHeight += Time.deltaTime * m_HeightSpeed; if(m_NowHeight > (m_MaxScrollHeight - (m_NowHeight / 2.0f))) { isScroll = false; m_NowHeight = 0; } SetHeight(); } } private void SetHeight() { GetComponent().anchoredPosition = new Vector3(0, m_NowHeight,0); } }