您当前的位置: 首页 >  unity

十幺卜入

暂无认证

  • 2浏览

    0关注

    119博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity3d C#用UGUI系统实现类似于哔哩哔哩(B站)的弹幕效果功能(含源码)

十幺卜入 发布时间:2022-05-05 17:18:27 ,浏览量:2

前言

弹幕的功能在一些,需要滚动显示文字信息的场景下,还是很有需要。这里就模拟实现一下类似于B站弹幕的效果。

效果

如图的效果: 在这里插入图片描述

实现过程

实现的思路是一个管理脚本,加上一个移动文本的脚本,管理脚本随机颜色、位置等信息,移动文字的脚本就单纯的控制自身从右至左的移动,移动到最左侧时,更新弹幕文字内容和颜色,从最右边随机个上下位置,一直重复该过程。

编写弹幕文本脚本
using UnityEngine;
using UnityEngine.UI;

//弹幕Text对象
[RequireComponent(typeof(Text))]
public class DanMuText : MonoBehaviour
{
    [Header("父节点和自己节点Rect")]
    public RectTransform PRect,MRect;
    [Header("Text组件")]
    public Text text;
    bool IsMove = false;
    float Posx, PosY;

    [Header("移动速度")]
    public float Speed = 180;
    // Start is called before the first frame update
    void Start()
    {
        if (text == null)
            text = GetComponent();
    }

    private void FixedUpdate()
    {
        if (IsMove)
        {
            transform.localPosition += Time.deltaTime * Vector3.left * Speed;

            if (transform.localPosition.x  DanMuTextList.Count)
        {
            for (int i = DanMuTextList.Count; i             
关注
打赏
1663314737
查看更多评论
0.0720s