gpt4 book ai didi

c# - 如何获取TextMeshPro组件

转载 作者:行者123 更新时间:2023-11-30 21:35:29 35 4
gpt4 key购买 nike

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引擎不能转换类型。

最佳答案

嗯,问题是 TextMeshProText 不是 TextMeshPro 对象,而是 TMP_Text,所以如果你试过这个:

TMP_Text mytext;
void Start () {
mytext = textobj.GetComponent<TMP_Text>();
}

现在您应该在 mytext 对象中获得一个值。

关于c# - 如何获取TextMeshPro组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49172311/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com