Open door with keypress

Hello, In my game i have a question that the player should answer to open a door when the answer right. i know how to make open a door with a key press. but i want to open a door with a word. for example if the answer of my question is '' unity '' so the player should write unity in a propriate zone to open the door. if he write another word so the door still not open. can i do this with unity, can i do it also with number so instead of press 1 for example the door will be open if i write 15423 for example, how can i do this please. it's very important for my game. big thanks

if you know how to do it on key-press, it should be obvious that whenever the player types in a word, and submits the results, you open it the same way you would on a key press, or mouse-click.

Text entry is easily done by using GUI.TextField, which allows a user to enter a single-line string. http://unity3d.com/support/documentation/ScriptReference/GUI.TextField.html

Then in the OnGUI function you can then check the string entered by the player for the correct answer.

It's important to remember that GUI.TextField is vulnerable to focus: the player will not be entering any text unless they click on the TextField first. To get around this, you can use GUI.FocusControl to set the focus specifically on the TextField, or away from the text field by focusing on another GUI.

Because using focus threw me for a loop the first time I tried it (I have a very similar text entry requirement in my game), I'll just give an example. It's in C#, but it's still very similar to JavaScript.

void onGUI() 
{    
    GUI.SetNextControlName("InputField");
    input_string = GUI.TextField(new Rect(10,10,80,20), input_string);
    GUI.FocusControl("InputField");
}

The java implementation would look something like this:

var input_string : String = " "; var correctAnswer;

onGUI() 
{    
    GUI.SetNextControlName("InputField");
    input_string = GUI.TextField(new Rect(10,10,80,20), input_string);
    GUI.FocusControl("InputField");
}

Update()
{
if (1 == Input.GetAxis ("Return") )
{
if (input_string == correctAnswer)
{
//Unlock Door
}
else
{
...
}