第一种刷新文字形式
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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 (otherName.Contains("LP"))