using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TextSpeed : MonoBehaviour
{
private float speed = 100;
public RectTransform maskRec;//text 父物体
public RectTransform rec;//text
float localX;
float localY;
float localZ;
float txtWidth;
// Start is called before the first frame update
void Start()
{
localY = transform.localPosition.y;
localZ = transform.localPosition.z;
//Debug.LogError(maskRec.rect.width);
if (maskRec!=null)
rec.anchoredPosition = new Vector2(maskRec.rect.width, 0);
}
// Update is called once per frame
void Update()
{
if (speed != 0)
{
if (rec != null)
txtWidth = rec.rect.width;
if (rec.anchoredPosition.x < -txtWidth)
{
rec.anchoredPosition = new Vector2(maskRec.rect.width, 0);
}
localX = transform.localPosition.x - speed * Time.deltaTime;
transform.localPosition = new Vector3(localX, localY, localZ);
}
}
}
unity 字幕滚动
关注
打赏