2025-03-11 15:30:07 +08:00

30 lines
702 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using UnityEngine.UI;
public class Marquee : MonoBehaviour
{
ScrollRect rect;
void Start()
{
//获取 ScrollRect变量
rect = GetComponent<ScrollRect>();
}
void Update()
{
//在Update函数中调扬蚂用之码祝ScrollValue函数
ScrollValue();
}
private void ScrollValue()
{
//当对应值超过1重新开始从 0 开始
if (rect.horizontalNormalizedPosition >= 1f)
{
rect.horizontalNormalizedPosition = 0;
}
//逐渐递增 ScrollRect 水平方向上的值
rect.horizontalNormalizedPosition = rect.horizontalNormalizedPosition + 0.2f * Time.deltaTime;
}
}