Unity—Input

Unity Input常用类&函数:

 TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true);

        Input.GetKey(KeyCode.A);

        Touch [] touch =Input.touches;


       if( Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { }

1.Input.touches 触摸列表

JavaScript ⇒ public static var touches: Touch[];
C# ⇒ public static Touch[] touches;

Description 描述

Returns list of objects representing status of all touches during last frame. (Read Only) (Allocates temporary variables).

返回代表上一帧所有的触摸状态的对象列表(只读)(分配临时变量)

Each entry represents a status of a finger touching the screen.

每个记录都代表着一个手指在屏幕上的触碰状态。

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Update() {
        int fingerCount = 0;
        foreach (Touch touch in Input.touches) {
            if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
                fingerCount++;
 
        }
        if (fingerCount > 0)
            print("User has " + fingerCount + " finger(s) touching the screen");
 
    }
}

2.TouchScreenKeyboard 触摸屏键盘

class in UnityEngine

Description 描述

Interface into the native iPhone, Android, Windows Phone and Windows Store Apps on-screen keyboards - it is not available on other platforms.

连接到本机iPhone、 Android、 Windows Phone 和 Windows 应用商店应用程序屏幕键盘-不是在其他平台上可用。

This interface allows to display different types of the keyboard: ASCII, Numbers, URL, Email, and others.

此接口允许显示不同类型的键盘︰ ASCII、 数字、 URL、 电子邮件,和其他的符号。

Because the appearance of the keyboard has the potential to obscure portions of your user interface, it is up to you to make sure that parts of your user interface are not obscured when the keyboard is being displayed.

因为键盘的外形有可能掩盖你的用户界面部分,它是由你来确保您的用户界面部分的键盘在显示时不会被遮盖。

TouchScreenKeyboard.visible and TouchScreenKeyboard.area should be used to determine if the keyboard is being shown (activated) and what portion of the screen is using.

TouchScreenKeyboard.visible和TouchScreenKeyboard.area应该用于决定是否显示(激活)该键盘并且使用屏幕的哪部分。

Static Variables 静态变量

areaReturns portion of the screen which is covered by the keyboard.
返回键盘覆盖的屏幕部分。
hideInputWill text input field above the keyboard be hidden when the keyboard is on screen?
当键盘在屏幕上时,该属性将会决定是否隐藏键盘上的文本输入区域。
isSupportedIs touch screen keyboard supported.
是否支持触摸屏键盘。
visibleReturns true whenever any keyboard is completely visible on the screen.
无论任何键盘在屏幕上完全可见都返回true。

Variables 变量

activeIs the keyboard visible or sliding into the position on the screen?
是否键盘可见或滑动到屏幕上的位置吗?
doneSpecifies if input process was finished. (Read Only)
指定是否输入的过程结束。(只读)
targetDisplaySpecified on which display the software keyboard will appear.
指定显示的键盘将会出现。
textReturns the text displayed by the input field of the keyboard.
返回显示键盘输入区域的文本。
wasCanceledSpecifies if input process was canceled. (Read Only)
指定是否取消输入进程(只读)。

Static Functions 静态函数

OpenOpens the native keyboard provided by OS on the screen.
打开操作系统提供的本地键盘。

转载于:https://www.cnblogs.com/bananana/p/8867492.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unity中的输入系统是用于处理用户输入的组件。它允许您捕获和响应用户键盘、鼠标和触摸屏输入。 在Unity中,您可以通过以下几种方式来处理输入: 1. 使用`Input`类:Unity提供了一个名为`Input`的静态类,您可以使用它来检测用户按下的键、鼠标按钮以及触摸屏上的触摸手势。您可以在脚本中使用`Input.GetKey`、`Input.GetMouseButton`和`Input.GetTouch`等函数来检测输入事件。 2. 使用事件系统:Unity提供了一个事件系统,通过将输入事件绑定到特定的函数上,您可以使用事件触发器来处理输入。例如,您可以使用`EventTrigger`组件来在用户点击按钮时触发相关功能。 3. 使用自定义输入管理器:如果您需要更高级的输入控制,您可以编写自己的输入管理器。您可以通过继承`MonoBehaviour`类并重写`Update`函数来实现自定义逻辑,然后在脚本中访问输入管理器的实例来处理输入。 无论您选择哪种方法,处理输入的一般流程如下: 1. 捕获用户输入:使用合适的方法检测用户的键盘、鼠标或触摸屏输入。 2. 响应输入:根据用户的输入来执行相应的操作。这可以是移动游戏对象、触发特定的事件或执行其他逻辑。 3. 更新游戏状态:根据输入的结果来更新游戏状态,例如更新玩家位置、改变游戏进程或进行其他操作。 Unity的输入系统非常灵活,可以轻松处理各种用户输入。根据您的需求和项目类型,选择最合适的方法来处理输入。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值