直播平台开发,动态文字输出,文字自动输出

直播平台开发,动态文字输出,文字自动输出

 

public class gamebeijin : MonoBehaviour
{
    public float textShowTime_Second = 0.2f;
    private string content = "传说,在远古的时候,天地之间只有几丈高,天上有七个太阳和七个月亮,太阳把大地烧得滚烫烫的。百姓叫苦连天。这时有一个黎族大力神挺身而出......";
    public bool isActive = false;//是否正在输出
    private float timeCount;
    public Text targetText;
    private int currentPos = 0;
    void Update()
    {
        StartCoroutine(StarWrite());
    }
    [ContextMenu("TestShow")]
    public float StarShow(string str)
    {
        timeCount = 0;
        isActive = true;
        content = str;
        targetText.text = "";
        return timeCount * content.Length;
    }
    public void OffShow()
    {
        isActive = false;
        timeCount = 0;
        currentPos = 0;
        targetText.text = content;
    }
    IEnumerator StarWrite()
    {
        if (!isActive) yield break;
        timeCount += Time.deltaTime;
        if (timeCount >= textShowTime_Second)
        {
            timeCount = 0;
            currentPos++;
            if (currentPos > content.Length)
            {
                OffShow();
            }
            else
            {
                targetText.text = content.Substring(0, currentPos);
            }
        }
    }
}

以上就是直播平台开发,动态文字输出,文字自动输出, 更多内容欢迎关注之后的文章

 

posted @ 2022-05-10 14:15  云豹科技-苏凌霄  阅读(100)  评论(0)    收藏  举报