首页 > 技术文章 > Unity基础-Input接口

carious 2019-05-06 16:46 原文

input

底层的设备输入接口,在开发中很少用到

Input.GetKey()

// Update is called once per frame
void Update () {
    if (Input.GetKey(KeyCode.A))
    {
        Debug.Log("get key a");
    }
    if (Input.GetKeyDown(KeyCode.A))
    {
        Debug.Log("get key down a");
    }
    if (Input.GetKeyUp(KeyCode.A))
    {
        Debug.Log("get key up a");
    }
}

Input.GetButton(),Input.GetButtonDown(),GetButtonUp()类似

Input.touches 触屏

Touch[] touches Input.touches;
foreach(Touch t in touches)
{
    t.fingerId;
    t.deltaPosition;
    t.deltaTime;
    t.phase;
    t.position;
}

TouchScreenKeyboard.Open 触屏输入

TouchScreenKeyboard t = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default);
    

推荐阅读