簡體   English   中英

單擊按鈕后如何從按鈕中獲取文本?

[英]How do I get the text from a button after clicking it?

我正在嘗試獲取單擊按鈕的文本以將其與字符串進行比較。

public void clicked()
{

    Debug.Log("Timer done");
    secondsLeft = 0;
    timerOn = false;

    questionUI.SetActive(false);
    Paused = false;
    //turns off the question screen

    string answer = GetComponentInChildren<TMPro.TMP_Text>().ToString();
    if (questions[0] == answer)
    {
        PlayerQuests.points += 1000;
    }

}

這是我編寫的代碼,按鈕在單擊后運行。 這應該獲取按鈕內的文本( TextMeshProUGUI並將其與另一個字符串進行比較。

如果您using TMPro; 在您的課程頂部,您應該能夠通過編寫以下內容來獲取TextMeshProUGUI組件的文本:

var answer = GetComponentInChildren<TextMeshProUGUI>().text;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM