您当前的位置: 首页 >  unity

云小川

暂无认证

  • 5浏览

    0关注

    78博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

unity 字幕滚动

云小川 发布时间:2022-07-14 15:20:45 ,浏览量:5

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);
        }
    }
}

关注
打赏
1663746399
查看更多评论
立即登录/注册

微信扫码登录

0.9236s