我想获取当前显示页面的TextMeshProUGUI组件的文本。我尝试过:
foreach (var page in InstructionText.textInfo.pageInfo)
{
Debug.Log(page.firstCharacterIndex + " : " + page.lastCharacterIndex);
m_TextsPerPage.Add(InstructionText.text.Substring(page.firstCharacterIndex, page.lastCharacterIndex - page.firstCharacterIndex + 1));
}
使用
private List<string> m_TextsPerPage = new List<string>();
但是无论哪个输入,page.firstCharacterIndex
和page.lastCharacterIndex
均为0。
答案 0 :(得分:0)
标记您的uiGUI。搜索标签GameObject.FindObjectWithTag()
,然后执行GetComponent<TextMeshProUGUI>()
然后您可以访问/读取/更改其.text
答案 1 :(得分:0)
page.firstCharacterIndex
和page.lastCharacterIndex
可以工作,但是它们的值不会立即更新,因此您必须等到它们更新后才能添加收益来解决问题:
while (InstructionText.textInfo.pageInfo[0].lastCharacterIndex == 0)
yield return null;