0

I'm having an issue with a simple IF statement:

string a = GameObject.Find("Text").GetComponent<TextMeshProUGUI>().text;
Debug.Log(a);
if (a == "test")
   GameObject.Find("PracticeButton").GetComponent<Button>().enabled = true;

The expression evaluates as false even thou i can clearly see that the values are the same. right and left side are equal

Does anyone have any idea why this happens? I've tried String.Equals but have the same result.

Devin L.
  • 437
  • 2
  • 12
gorokizu
  • 2,538
  • 2
  • 20
  • 26
  • 2
    you might have a hidden character in that string. like described in [this post](https://stackoverflow.com/a/25999691/5174469). Try to compare `a.Length == "test".Length` what does this return? – Mong Zhu Aug 24 '17 at 16:33
  • the post suggests to use the `CompareTo` method. It would ignore hidden characters – Mong Zhu Aug 24 '17 at 16:35
  • Variable a seems to have 5 characters compared to 4. – gorokizu Aug 24 '17 at 16:38
  • While @MongZhu comment seems to be the solution, I do suggest you delete the text in the `TextMeshProUGUI` and retype it again. If possible, copy the "test" from the `if` statement and paste it to the `TextMeshProUGUI`. – Programmer Aug 24 '17 at 16:38
  • 1
    I cannot tell you how it got in, but if the answer from the post helps you I will mark this question as duplicate. – Mong Zhu Aug 24 '17 at 16:40
  • yes thank you, i'll have to investigate why TextMeshPro adds a character – gorokizu Aug 24 '17 at 16:40

0 Answers0