Input fields
Let players enter text with the Input Field element in your Unity Spark UI.
Read time 1 minuteLast updated 3 hours ago
An input field is a box that the player enters text into, such as the answer to a riddle, or a secret code that unlocks a door. A new input field shows the hint until the player types.
Enter text...Input field settings
The Input Field component contains the following main settings.
Setting | Description |
|---|---|
| Text | Sets the text in the field. |
| Character Limit | Limits the number of characters the player can type. |
| Content Type | Sets what the player can type, such as any text, whole numbers only, or masked text for passwords. |
| Line Type | Determines whether the field holds one line or several. |
| Placeholder | Sets the hint text that shows when the field is empty. To change the hint, select the placeholder text inside the field. |
| Read Only | Shows text that the player can't change. |
| On Focus Select All | Selects all the text when the player selects the field. |
Buttons, sliders, toggles, input fields, and scrollbars share the following settings.
Setting | Description |
|---|---|
| Interactable | Sets whether the player can use the control. When Interactable is disabled, the control shows its Disabled Color. |
| Colors | Sets the tint for each state: Normal Color, Highlighted Color (when the pointer is over it), Pressed Color, Selected Color, and Disabled Color. Color Multiplier brightens every state, and Fade Duration sets how long a change takes. |
Use the text the player enters
To use the text, ask the AI assistant, for example, You can also use a script. The field's holds what the player typed. The following events pass the current text to your function.
Open the vault door when the player types the code 1234.textEvent | When it happens |
|---|---|
| Each time the text changes. |
| When the player presses Enter. |
| When the player finishes editing, for example, by selecting somewhere else. |
local function onCodeEntered(text) -- check the code the player typedendcodeField:OnSubmit(onCodeEntered)
Pass a function that you define in the same script. Don't pass , because the event calls the function you give it.
self