using DG.Tweening; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine; public class ScrollImage : MonoBehaviour { [SerializeField] private float m_PerImageSize; [SerializeField] private float m_PerImageSpace; [SerializeField] private int m_ImageCount; private int nowImageIndex = 0; private float jumpTime = 3; private float realTime = 3; private RectTransform m_RectTrans; private float m_TargetPosX = 0; // Start is called before the first frame update void Start() { realTime = Time.time; m_RectTrans = GetComponent(); } // Update is called once per frame void Update() { float a = Time.time - realTime; if(a >= jumpTime) { realTime = Time.time; //切换 nowImageIndex++; if(nowImageIndex >= m_ImageCount) { nowImageIndex = 0; } JumpToIndex(); } } /// /// 跳转到对应的章节 /// private void JumpToIndex() { float posY = m_RectTrans.anchoredPosition.x;//当前尺寸 m_TargetPosX = posY - m_PerImageSize - m_PerImageSpace; if(m_TargetPosX < -(m_PerImageSize * m_ImageCount)) { m_TargetPosX = 0; } m_RectTrans.DOAnchorPosX(m_TargetPosX, 0.6f); } }