簡體   English   中英

(統一)我的文本界面未更新

[英](Unity) My Text UI not updating

好的,所以,我嘗試進行類似測驗的操作,其中必須將字符串數組顯示給Text UI。 問題是,在我正確回答問題后,問題會在檢查器中更新,但是在游戲屏幕上卻沒有。 可能是一個菜鳥錯誤,對不起,我是新手。

    public string[] quesitons = new string[] { "2+2 = ?", "1+1 = ?", "3+3 = ?" };
    public string[] answers = new string[] { "4", "2", "6" };
    public int i = 0;

    [SerializeField]
    private InputField _input;

    //Main
    public string currentQ;
    public string currentA;

    public Text questionText;


    public void GetInput(string input)
    {
        if (input == answers[i])
        {
            Debug.Log("Correct");
            i++;
            questionText.text = quesitons[i];
            currentQ = quesitons[i];
            currentA = answers[i];
        }
        else
        {
            Debug.Log("Wrong");
        }
    }

    void Start()
    {
        currentQ = quesitons[i];
        questionText.text = quesitons[i];

        currentA = answers[i];
    }
}

在此處輸入圖片說明

您發布的代碼應該可以使用。 也許您錯過了GetInput函數中的文本更新行? 無論如何,我在這里發布了重構代碼。 用下面的代碼替換GetInput和Start函數,然后進行測試。

public void GetInput(string input) {
    if (input == currentA) {
        Debug.Log("Correct");
        i++;
        LoadQuestionAnswer();
    }
    else {
        Debug.Log("Wrong");
    }
}

void Start() {
    LoadQuestionAnswer();
}

void LoadQuestionAnswer() {
    currentQ = quesitons[i];
    currentA = answers[i];
    questionText.text = currentQ;
}

暫無
暫無

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

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