简体   繁体   English

比较两个 UI 文本的统一性

[英]Comparing two UI text unity

Hello I'm trying to compare my two UI Text but somehow it wont compare with each other你好,我正在尝试比较我的两个 UI 文本,但不知何故它不会相互比较

    if (WordMatch.text == WordGenerator.text) 
    {
        Debug.Log ("Hello");
    }

Here is my code for comparing the two UI Text.这是我用于比较两个 UI 文本的代码。

    TextAsset wordText = Resources.Load<TextAsset> ("Words");

    name = wordText.text.Split ("\n" [0]);

    WordGenerator.text = name [Random.Range (0, name.Length)];

And here is the code where I get the value of my "WordGenerator"这是我获得“WordGenerator”值的代码

Thank you for your time :).感谢您的时间 :)。

It could have been because of the encoding of your asset file.这可能是因为您的资产文件的编码。

You can use this function instead of "==" for comparing您可以使用此函数代替“==”进行比较

private bool AreEqual(string val1,string val2)
{
    if(val1.Length != val2.Length)
        return false;

    for (int i = 0; i < val1.Length; i++)
    {
        var c1 = val1[i];
        var c2 = val2[i];
        if (c1 != c2)
            return false;
    }

    return true;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM