I’m trying to turn an InputField into a command prompt like thing, but I’m stuck on one thing: Command prompts have a little prompt before the user input space like “C:/>” or something like that. I can put the prompt in the field pretty easily, but I can’t seem to figure out how to keep it there and avoid the player deleting it. If I extend InputField, I can’t override the important Backspace() and MoveTextStart() methods. If I code from outside the InputField, I can’t seem to find a way to influence the backspace behavior. OnValidateText() seems to only apply to text, not backspacing, and no other events seem to apply. Is there a way to do what I want to do?
I can think of two ways - register a handler for the OnValueChanged event and whenever the prompt characters are removed, put them back.
The other way to do this is probably easier:
When you add an InputField to your scene you’ll see it has two child objects (Text and Placeholder).
First, add a new Text object as a child of the InputField and position it on the left of the input field. This is for your prompt.
Then resize the text and placeholder objects to make space for it and so that the text doesn’t overlap the prompt.
