- Home /
textField - disable enter? how to
how to disable enter in the text field, when pressed input goes up if there is more characters left... or to make it trully one line...any ideas are welcome, thanks!
Answer by jahroy · Dec 13, 2011 at 06:18 PM
This should work.
It gets the text from the TextField, then replaces newline characters with nothing.
var theText : String = "Enter text";
function OnGUI () { theText = GUI.TextField(someRectangle, theText); theText = theText.Replace("\n"[0], ""); }
Remember that you are the one passing the variable to the TextField function every frame, so you can do anything you want to the value of the string.
You could even do it all in one line if you want to be one of those programmers who thinks it's better to do it that way:
theText = GUI.TextField(someRect, theText).Replace("\n"[0], "");
it gives me this error: BCE0023: No appropriate version of 'String.Replace' for the argument list '(char, String)' was found.
i could not get around it...any ideas?
i managed to do it like this:
theText = theText.Replace(("\n"[0]).ToString(), "");
I gave you the UnityScript / Javascript version.
It may not work in C#...
If you're using C#, you can probably do it the normal way:
theText = theText.Replace("\n", "");
The UnityScript version requires a weird syntax because there is no char datatype.
Your answer
![](https://koobas.hobune.stream/wayback/20220613062038im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to call function when enter is pressed in text area? 2 Answers
Text.Field erratically updating 0 Answers
How does "Input.eatKeyPressOnTextFieldFocus" work on compilation ? 1 Answer
How to slow down GUI 2 Answers
Submit inputField when Enter is clicked 10 Answers