- Home /
Question by
TharinduTpd · Jun 05, 2013 at 06:46 AM ·
monodevelopevent-handlingtextbox
Enter Key press event detect from textbox - Unity3D - C#
i am doing a project with Unity3D . in the interface there is a textbox. once user input some text and and press enter key then i want to read the text in text box. so please tell me how to programmatically detect the key press event in unity3D - C# using MonoDeveloper.
Comment
Answer by robertbu · Jun 05, 2013 at 03:52 PM
Try this:
public class EnterKey : MonoBehaviour {
string text = "";
void OnGUI () {
if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
Debug.Log ("Enter key pressed");
text = GUI.TextArea(new Rect(0,0,200,200),text);
}
}