Reputation: 81
I'm making a game where the user inputs a code, and if the code is correct, it opens a door. So, I made a InputField where the user inputs his answer and then I take his answer and compare it in this code:
public TextMeshProUGUI input;
public string answer;
public void retrieveText()
{
string userInput = input.text;
//the code is made of letters so I make it all caps to not make it case sensitive
userInput.ToUpper();
if (userInput.Equals(answer))
{
//do stuff
}
However, userInput.Equals(answer) always returns false, no matter what I try. I tried removing the ToUpper() function, using userInput == answer, and nothing works. if I use Debug.Log to see what userInput returns, it returns the correct answer. I hope someone can help me. Any help is much appreciated!
Upvotes: 3
Views: 1172
Reputation: 81
Found it! As it turns out, you must use TMP_InputField
class and not TextMeshProUGUI
to extract your text. Change that and everything works fine.
Upvotes: 5