C# Unity - How can I clear an InputField

前端 未结 1 951
无人共我
无人共我 2021-01-25 09:46

I want to clear an InputField in Unity, but I cant get it to work. What I do now is:
public InputField inputfieldname; inputfieldname.text = \"\";

相关标签:
1条回答
  • 2021-01-25 10:38

    This problem does not exist in the current version of Unity I am running. My advice to you is to update to 5.4.. If you don't want to, then you can select the InputField with code then clear it.

    public InputField inputfieldname;
    inputfieldname.Select();
    inputfieldname.text = "";
    

    You can make this into an extension method.

    public static class Extension
    {
        public static void clear(this InputField inputfield)
        {
            inputfield.Select();
            inputfield.text = "";
        }
    }
    

    Now you can use it like below:

    public InputField inputfieldname;
    inputfieldname.clear();
    
    0 讨论(0)
提交回复
热议问题