简体   繁体   中英

Comparing two UI text unity

Hello I'm trying to compare my two UI Text but somehow it wont compare with each other

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

Here is my code for comparing the two UI Text.

    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"

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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