using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //提示文字控制类 public class PromptTextCtrl : MonoBehaviour { Text text; // Start is called before the first frame update void Awake() { text = this.GetComponent(); HideText(); } public void SetPrompt(string msg, Color textColor,float time=0) { if (text == null) text = this.GetComponent(); text.color = textColor; text.text = msg; if (time != 0) { if (IsInvoking("HideText")) CancelInvoke("HideText"); Invoke("HideText", time); } } private void HideText() { text.text = ""; } //被隐藏时 清空文字 取消Invoke private void OnDisable() { CancelInvoke(); HideText(); } }