问题
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