_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Battle_Royale/ContentMove.cs
2024-11-27 18:05:26 +08:00

33 lines
940 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ContentMove : MonoBehaviour
{
public RectTransform content; // Scroll View的Content
public float speed; // 滚动速度
private float startPositionX;
public RectTransform startpos;
// Start is called before the first frame update
void Start()
{
startPositionX = startpos.anchoredPosition.x;
speed = 225f;
}
// Update is called once per frame
void Update()
{
// 滚动Content
content.anchoredPosition += Vector2.right * speed * Time.deltaTime;
// 当Content离开可视区域时重置位置
if (content.anchoredPosition.x + content.rect.width / 2 > content.rect.width)
{
startPositionX = startpos.anchoredPosition.x- content.rect.width;
content.anchoredPosition = new Vector2(startPositionX, content.anchoredPosition.y);
}
}
}