直播平臺開發,動態文字輸出,文字自動輸出
阿新 • • 發佈:2022-05-10
直播平臺開發,動態文字輸出,文字自動輸出
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);
}
}
}
}
以上就是直播平臺開發,動態文字輸出,文字自動輸出, 更多內容歡迎關注之後的文章