繁体   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