I need to make an InputField for my game, where a player will be writing the answer for the puzzle they will have on the screen.
This InputField need to check if the text that player wrote is the same as string in the script.
I have tried writing things like getcomponent
from the text in inputfield
and checking it with "if" but its not working.
Can someone help out with a sample of how to get the text from an InputField?
You can get the text of the InputField with Inputfield.text
the detailed Explanation is in the Api-Doc https://docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.InputField-text.html
With that it is just a comparison if two Strings are equal.
In Code it could look like this:
public InputField input;
public void Start()
{
if(input.text == "Text to Compare"){
}
}
And for the Future, it´s always nice if you post your own Code. It´s much easier to get a grasp of the Situation then.
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.