Not able to get TextMeshPro text to variable slot in Unity

本小妞迷上赌 提交于 2021-02-05 12:19:14

问题


using TMPro;

public TextMeshPro _livesText;
public TextMeshPro _scoreText;

I am unable to drag the text from the Hierarchy to the variable slot in Inspector. Why is it happening. Please help.


回答1:


You seem to speak about a TextMeshProUGUI which in the Inspector is called TextMeshPro - Text(UI).

Note that TextMeshPro != TextMeshProUGUI!

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

So either make it

public TextMeshProUGUI _livesText;
public TextMeshProUGUI _scoreText;

or go for the parent class

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.



来源:https://stackoverflow.com/questions/64275690/not-able-to-get-textmeshpro-text-to-variable-slot-in-unity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!