Help with GUI Box

Here is my code:

using UnityEngine;
using System.Collections;
public class MyGUI : MonoBehaviour {
** public string textFieldString = “> Type Here…”;**
** void OnGUI(){**
** textFieldString = GUI.TextField( new Rect(0, 880, Screen.width, 25), textFieldString);**
** if(Input.GetKeyDown(KeyCode.Return))**
** {**
** if(textFieldString.Contains(“open door”))**
** {**
** //make a GUI box appear that says “You open the door!”**
** GUI.Box( new Rect(0, 0, Screen.width, 50), “You open the door”);**
** }**
** }**
** }**
}

I want a GUI box to appear when I type open door and press enter, but it doesn’t seem to want to work.
can anyone tell me whats wrong with it?

Please help me! I don’t know what to do! :cry:

Wow, just 31 minutes before bumping your own post!
You should use code tags to make your code readable :wink:

using UnityEngine;
using System.Collections;

public class MyGUI : MonoBehaviour {

    private const string DefaultCommandPrompt = "> Type Here...";

    private string textFieldString = DefaultCommandPrompt;
    private bool showOpenDoorBox;

    private void OnGUI(){
        textFieldString = GUI.TextField( new Rect(0, 880, Screen.width, 25), textFieldString);

        if (Event.current.type == EventType.KeyDown  Event.current.keyCode == KeyCode.Return) {
            // Accept user input upon tapping return key.

            // Could perform string checks here for slight performance improvement.
            if (textFieldString.Contains("open door"))
                showOpenDoorBox = true;

            // Reset prompt for next command.
            textFieldString = DefaultCommandPrompt;
        }
        
        if (showOpenDoorBox) {
            //make a GUI box appear that says "You open the door!"
            GUI.Box(new Rect(0, 0, Screen.width, 50), "You open the door");
        }
    }
}

I haven’t tested the above, but it should work :slight_smile: