public class ClickBub : MonoBehaviour {
int x;
int count;
TextMeshPro mytext;
TextMeshPro soretext;
GameObject textobj;
// Use this for initialization
void Start () {
textobj = this.gameObject.transform.GetChild (0).gameObject;
mytext = textobj.GetComponent<TextMeshPro>();
在这个 mytext 中是一个空值。如何将 TextMeshValue 分配给变量?
还说unity引擎不能转换类型。
最佳答案
嗯,问题是 TextMeshPro 的 Text 不是 TextMeshPro 对象,而是 TMP_Text,所以如果你试过这个:
TMP_Text mytext;
void Start () {
mytext = textobj.GetComponent<TMP_Text>();
}
现在您应该在 mytext 对象中获得一个值。
关于c# - 如何获取TextMeshPro组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49172311/