首页 > 解决方案 > 从 TouchScreenKeyboard 获取按键

问题描述

如何使用 TouchScreenKeyboard 访问单个按键?我试过了

if (Input.GetKey(KeyCode.A))
     UIActions.DebugText("The A Key was pressed!!");

但它没有返回任何东西。这个类似乎只有最少数量的方法可用。这样做的正确方法是什么?

using UnityEngine;

public class FullKeyboardUserInput : MonoBehaviour
{
    private TouchScreenKeyboard mobileKeys;

    void Start()
    {
        mobileKeys = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, false, true);
    }

    private void Update()
    {
        if (mobileKeys != null && mobileKeys.done)
        {
            GameManager.CurrentDriftName = mobileKeys.text;
            UIActions.DebugText(GameManager.CurrentDriftName);
            UIActions.NumKeyboardView(GameManager.instance.NumKeyboardUserInputView);
            Destroy(gameObject);
        }

        if (Input.GetKey(KeyCode.A))
        {
            UIActions.DebugText("The A Key was pressed!!");
        }

        if (mobileKeys != null && mobileKeys.wasCanceled)
        {
            Destroy(gameObject);
        }
    }
}

标签: c#iphoneunity3dkeyboard

解决方案


触摸键盘并不是一种输入击键的方式,它是一种输入文本的方式 - 您始终可以使用 InputField


推荐阅读