Unity3D 之UGUI 文本框和编辑框InputField

首先创建一个文本Text

然后是文本相对应的属性

这里的属性比较的简单,一些基本的颜色,格式,字体加粗,字体大小,都有。如果需要字体文件,还可以从计算机的控制面板里进行导入。

然后是输入框

InputField游戏对象下面包括两个元素,一个是提示内容,一得到输入的内容

注意这里需要 有一个接收输入的设备,不然是不能响应输入的。

Placecholder 提示的输入内容。

Text 得到输入的内容。

来说明几个经常使用的功能

Pressed color -->按下颜色

Chatacter Limit -->控制输入长度

Content Type -->输入类型

Highlighted Color-->高光   

Read Only -->只读

下面讲解一下通过脚本获取值和设置值的方法,和一般获取组件的方法一样

有时候直接通过

this.GetComponent<Text>()

 会获取不到

那么在引入下面后就能够获取到了

using UnityEngine.UI;
Debug.LogError(this.GetComponent<Text>().text);

1

2

GameObject go = GameObject.Find("mzxg");

go.GetComponent<InputField>().text = hitInfo.transform.parent.GetComponent<TextMesh>().text;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

using UnityEngine.UI;

using UnityEngine.EventSystems;

using UnityEngine;

public class btn1 : MonoBehaviour

{

    // Start is called before the first frame update

    public Button btn;

    void Start()

    {

    }

    // Update is called once per frame

    void Update()

    {

        GameObject go = GameObject.Find("Butt");

        Text text=go.GetComponentInChildren<Text>();

        text.text="天桑在玩CSGO";

        Debug.Log(text.text);

    }

}

  

猜你喜欢

转载自blog.csdn.net/qq_21743659/article/details/128528926