- Home /
Add letters to string without 26 if-statements?
Hello, I'm trying to make an in-game search bar, but for that I would need every letter key pressed to be added on to the field. I know a way to do this, but I know that there is definitely a better way.
if (Input.GetKeyUp("a")){
SearchField = SearchField + "a";
}
^Bad way to do this^
Answer by Commoble · Jan 28, 2018 at 08:07 PM
You want to use Input.inputString
https://docs.unity3d.com/ScriptReference/Input-inputString.html
This field contains a string consisting of all the ASCII keyboard characters the player has pressed this frame. It also includes backspace and newline characters, which you can check for and handle accordingly.
I decided to use the Input Field object ins$$anonymous$$d.
Your answer
Follow this Question
Related Questions
Searching XML document 2 Answers
Restricting input field to predefined words 1 Answer
Search A String For Keyword - Profanity 2 Answers
Assigning Triangles from String Array issue 0 Answers
search is not a member of string 2 Answers