Documentation

Unity Spark

Open Unity Spark

Unity Spark

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
Enter text...
until the player types.

Input field settings

The Input Field component contains the following main settings.

Setting

Description

TextSets the text in the field.
Character LimitLimits the number of characters the player can type.
0
means no limit.
Content TypeSets what the player can type, such as any text, whole numbers only, or masked text for passwords.
Line TypeDetermines whether the field holds one line or several.
PlaceholderSets the hint text that shows when the field is empty. To change the hint, select the placeholder text inside the field.
Read OnlyShows text that the player can't change.
On Focus Select AllSelects all the text when the player selects the field.
Buttons, sliders, toggles, input fields, and scrollbars share the following settings.

Setting

Description

InteractableSets whether the player can use the control. When Interactable is disabled, the control shows its Disabled Color.
ColorsSets 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,
Open the vault door when the player types the code 1234.
You can also use a script. The field's
text
holds what the player typed. The following events pass the current text to your function.

Event

When it happens

OnValueChanged
Each time the text changes.
OnSubmit
When the player presses Enter.
OnEndEdit
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
self
, because the event calls the function you give it.

Additional resources