unity 中让Text的文字动态刷新形式

本文介绍了在Unity中实现Text组件文字内容动态刷新的两种方法,包括基本设置和可能的应用场景,帮助开发者创建动态显示的游戏UI。

 

第一种刷新文字形式

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class SensorTextRefresh2
{

    // Use this for initialization
    string showstring;
    public Text _text;
    public string otherName = "normal";
    string current;
    RefreshState refreshState;
    int index = 0;

    public void Init(Text _t, string _s, int _index, string _otherName)
    {
        refreshState = RefreshState.start;

        _s = float.Parse(_s).ToString("0.00");

        if (index == 0)
        {
            showstring = _s;
            current = _s;

        }
        else if (index == 1)
        {

            //if (_text.transform.parent.name == "transmitter" || _text.transform.parent.name == "temperature1")
            {
                showstring = _s;
                current = _s;
            }
            //else
            //{

            //    showstring = _s + "℃";
            //    current = _s + "℃";
            //}

        }
        else
        {

        }
        _text = _t;

        index = _index;
        otherName = _otherName;


        //Debug.LogError( "     " + _text.transform.parent.parent.parent.name);



    }

    public void SetString(string _s)
    {
        //if (refreshState == RefreshState.start)
        {
            _s = float.Parse(_s).ToString("0.00");

            if (index == 0)
            {
                current = _s;
                _text.text = "";
                _text.text = current;
            }
            else if (index == 1)
            {
                current = _s;

                _text.text = "";

                //if (otherName.Contains("PP"))
                //{

                //    Debug.LogError("    " + _text.text);

                //}
                //if (otherName.Contains("TP"))
                //{

                //    Debug.LogError("    " + _text.text);

                //}
                //if (other
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值