获得输入字段文本Unity3D用C# [英] Get text from Input field in Unity3D with C#

查看:2529
本文介绍了获得输入字段文本Unity3D用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到一个inputField内的文本在 Unity3D C#

I'm trying to get a text inside an inputField in Unity3D with C#.

我已经下了inputField在我的编辑,重命名,并在标签: Username_field

I've placed an inputField in my editor, renamed and tagged in: Username_field.

我的问题是:我怎样才能得到里面的文字 InputField Username_field C#脚本?

My question is: How i can get the text inside the InputField Username_field in a C# script?

感谢:)

推荐答案

在下方附上monobehaviour脚本您InputField游戏对象:

Attach below monobehaviour script to your InputField gameObject:

public class test : MonoBehaviour {
    void Start ()
    {
        var input = gameObject.GetComponent<InputField>();
        var se= new InputField.SubmitEvent();
        se.AddListener(SubmitName);
        input.onEndEdit = se;

        //or simply use the line below, 
        //input.onEndEdit.AddListener(SubmitName);  // This also works
    }

    private void SubmitName(string arg0)
    {
        Debug.Log(arg0);
    }
}



另请参阅下面的动画:

See also below animation:

这篇关于获得输入字段文本Unity3D用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆