无法将TextMeshPro文本获取到Unity中的可变插槽 [英] Not able to get TextMeshPro text to variable slot in Unity
问题描述
using TMPro;
public TextMeshPro _livesText;
public TextMeshPro _scoreText;
我无法将文本从层次结构拖动到Inspector中的可变插槽.为什么会这样呢.请帮忙.
I am unable to drag the text from the Hierarchy to the variable slot in Inspector. Why is it happening. Please help.
推荐答案
您似乎在说一个 TextMeshProUGUI
,在检查器中称为 TextMeshPro-Text(UI)
You seem to speak about a TextMeshProUGUI
which in the Inspector is called TextMeshPro - Text(UI)
.
请注意, TextMeshPro
!= TextMeshProUGUI
!
Note that TextMeshPro
!= TextMeshProUGUI
!
这两个之间没有继承.(类似于Unity在 TextMesh
和 UI.Text
中构建)
There is no inheritance between those two. (Similar to Unity build in TextMesh
and UI.Text
)
If you want one general field for both types then you need to use the common parent type TMP_Text
所以要么做到
public TextMeshProUGUI _livesText;
public TextMeshProUGUI _scoreText;
或参加父课程
public TMP_Text _livesText;
public TMP_Text _scoreText;
如果仍然不是您的情况,那么您似乎正在尝试通过检查器"将场景中的层次结构"对象的引用分配给资产中的预制件.这是不允许的.反之亦然.
If this still isn't your case then you seem to be trying to assign a reference from a Hierarchy object in the scene via the Inspector to a prefab in the assets. This is not allowed. Only the other way round.
这篇关于无法将TextMeshPro文本获取到Unity中的可变插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!