How can I reset the placeholder of an input field back to the default readout?
Hello everyone,
I have a standard UI input field that I got from GameObject>UI
I modified the placeholder to read "PRESS TO PICK NAME" and I have a userName string that stores the name entered.
When I reset the userName to "GUEST" I want the placeholder to read "PRESS TO PICK NAME" again, but instead I still see the latest userName that was entered.
Another thing I've noticed is that when I restart the game the placeholder does read "PRESS TO PICK NAME" again.
Any ideas on to how I can get the placeholder back to the default value/text without having to restart?
Answer by donimation · Dec 12, 2016 at 08:08 PM
Got it!
using UnityEngine.UI;
Create the reference container like this.. DON'T use GameObject or Text, but InputField!
public InputField inputFieldRef;
In the inspector make sure you drag the WHOLE inputField Layer/Group/GO not just the Text child. Then, yes this works!
inputFieldRef.text = "";
@getyour411 I know this is what you probably meant. but I think/hope this answer might be more helpful to a Noob like me!;) Cheers!
Answer by getyour411 · Dec 10, 2016 at 02:39 AM
Create a reference to the input field.text field and set that to ""
@getyour411 I've been trying to do that like this:
Creating a public Text inputFieldRef in my script;
In the editor I drag the Text Object that is inside the inputField GO onto the script's empty slot.
in my reset method I include inputFieldRef.text = "";
I've even tried to do the same for the placeholder text, but the latest name I enter still shows up.
@getyour411 hmm... I think the problem may be that I'm referencing just the Text object inside the inputField ins$$anonymous$$d of the whole inputField and then pointing to it's text. Trying to figure out the proper syntax.. [edit: in C#]
Your answer
Follow this Question
Related Questions
Remap keyboard/keys for InputField 0 Answers
Prevent escape key from deleting InputField contents, have it save instead? 4 Answers
Blurry text on InputField C# 0 Answers
how to use scientific values in inputfield unit or restrict only some letters 0 Answers
How to hide/reset a Text object (without disabling) 2 Answers