本文介绍了C#Unity-如何清除InputField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Unity中清除InputField,但无法使其正常工作.我现在要做的是:
public InputField inputfieldname; inputfieldname.text = "";

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 = "";

,但是直到您选择它,它才会清除该字段.是否可以仅通过代码完全清除该字段?

but then it doesnt clear the field until you select it. Is it possible to clear the field totally just by code?

提前谢谢!亚伯洛斯

推荐答案

我正在运行的当前版本的Unity中不存在此问题.我的建议是将版本更新为5.4.如果您不想这样做,则可以选择带有代码的InputField,然后清除它.

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();

这篇关于C#Unity-如何清除InputField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 17:29