I'm making a game in Unity where the user selects a phrase from a list and receives a point if the phrase is correct.
The problem i'm having is despite selecting the right answer, when the code arrives to a switch it's right case does not match.
switch (answer.text)
{
case "it's a potato":
points ;
}
if I do a Debub.log(answer.text);
I get "it's a potato"
it's like answer.text
add some invisible extra character and do not match.
If I write the string manually then it works.
Can someone tell me what can I do with the string answer.text
to match the case please?
CodePudding user response:
Strings may be not equals if the end of first string is not equal \n. In this case you can try to check it, just to translating it to char array or byte array. And certainly don't forget to write break for any case.
CodePudding user response:
Indeed the string was being changed by adding a "\r"
at its end.
The solution I used was simply by doing:
anser.text.replace("\r", string.empty);
It worked like a charm. Thank you all for helping me!