当前位置:网站首页>[Unity Getting Started Plan] Basic Concepts (7) - Input Manager & Input Class
[Unity Getting Started Plan] Basic Concepts (7) - Input Manager & Input Class
2022-08-03 16:37:00 【flashinggg】
目录
1.3 Virtual Axis 虚拟轴(复数:Axels)
Ngative Button, Positive Button 负/正值键(按钮)
Input.GetKeyDown(string KeyName)
Input.GetKeyUp(string KeyName)
2.3 Access virtual axes Input.GetAxis(string AxisName)
在Input ManagerIn the window, you can view and define the project input axis and other related operations,Here is a brief introduction to what some of the controls it has mean.
1 Input Manager-Controls 控件
Input MnagerThe following three controls are mainly used
1.1 Key 键
Refers to any key on a physical keyboard,比如↑、W、Space空格等.
1.2 Button 按钮
Refers to the buttons on some physical controllers,Like on a gamepadX按钮.
1.3 Virtual Axis 虚拟轴(复数:Axels)
Maps to the buttons mentioned above/键,After the user activates the control,Virtual axes will get[-1,1]a value on the range.Unity中,Each project created contains several input shafts,在Input ManagerIn the window, you can view the properties that the input axis has.

Name 名称
轴的名称,可以在脚本中通过Nameaccess the axis.
Ngative Button, Positive Button 负/正值键(按钮)
Controls for pushing in the negative and positive directions, respectively,Can be a key on a keyboard,It could also be a button on the controller.Enter settings,对于键盘按键:(The default is on the keyboard, respectively“←”和“→”)
- Negative Buttion——负值键,Press to set the axis to-1
- Positive Button——正值键,Press to set the axis to1
对于游戏手柄:
The lever is on the left、中间、The right side sets the horizontal axis to -1、0和1.
The rest of the parameters will not be introduced too much here.
2 C#中的Input类
官方文档:UnityEngine.Input - Unity 脚本 API
如上,Unity中用InputThe class controls the user's input,包括键盘、鼠标、Some input methods such as gravity induction.以下介绍一些常用的InputAPI中的静态函数:
2.1 键盘的输入(获取键盘事件)
Input.GetKey(string KeyName)
当键名为KeyNamekey is held down(Long press is valid),返回true.Can be used for automatic fire etc.
if(Input.GetKey("up")){
print("up arrow key is held down");
}
Input.GetKeyDown(string KeyName)
when a key is pressed(按下有效)时,返回true.
Input.GetKeyUp(string KeyName)
When the user releases a key,返回ture
if (Input.GetKeyUp("space"))
{
print("Space key was released");
}2.2 鼠标的输入(获取鼠标事件)
Input.GetMouseButton(int button)
返回Whether the mouse is pressedbutton键,button值分别对应
- 0——鼠标左键
- 1——鼠标右键
- 2——鼠标中键
if (Input.GetMouseButton(0))
{
Debug.Log("Pressed left click.");
}
if (Input.GetMouseButton(1))
{
Debug.Log("Pressed right click.");
}
if (Input.GetMouseButton(2))
{
Debug.Log("Pressed middle click.");
}Input.GetMouseButtonDown(int button)
用户按下botton键的帧期间返回true
Input.GetMouseButtonUp(int button)
用户松开botton键的帧期间返回true
2.3 Access virtual axes Input.GetAxis(string AxisName)
public static float GetAxis (string axisName);
What it returns is a value,The meaning of this value depends on the type of control that the axis is mapped to.并且需要通过1.3properties described in NameThe axis name accesses the virtual axis.
For example, you want to query the value of the current horizontal axis and store it in a variable,就可以使用InputGetAxis(string AxisName)访问:
float horizontalInput = Input.GetAxis("Horizontal");The axis mapping is generally classified as touch screen(鼠标操作)、Keyboard operation class(键盘、控制杆).
鼠标操作
When the axes are mapped to the mouse,返回的float值不在[-1,1],此时的值为The current mouse increment*axis sensitivity.A positive value generally means that the mouse is to the right/向下移动,Negative values mean to the left/向上移动.
键盘操作
Joysticks for gamepads,-1Indicates pushing all the way to the left,1Indicates pushing all the way to the right,0表示在中间.
For physical keyboard operation,分为以下两种
- Vertical:Corresponds to the vertical of the keyboard,即上/下键,You can also customize key settings
- Horizontal:Corresponds to the level of the keyboard,即左/右键,You can also customize key settings
边栏推荐
猜你喜欢

为什么我强烈推荐使用智能化async?

一文看懂推荐系统:召回02:Swing 模型,和itemCF很相似,区别在于计算相似度的方法不一样

Analysis of ffplay video playback principle

虹科分享 | 如何测试与验证复杂的FPGA设计(3)——硬件测试

《社会企业开展应聘文职人员培训规范》团体标准在新华书店上架

中小微企业如何简单便捷、低成本实现数字化?360视觉云有妙招

【带你了解SDN和网络虚拟化】

世界顶级级架构师编写2580页DDD领域驱动设计笔记,属实有牌面
![[Unity Getting Started Plan] Basic Concepts (8) - Tile Map TileMap 02](/img/45/96af4ca21329964808a4c8f2b8272c.png)
[Unity Getting Started Plan] Basic Concepts (8) - Tile Map TileMap 02

Why do I strongly recommend using smart async?
随机推荐
【深度学习】今日bug(8月2)
TCP 可靠吗?为什么?
Kubernetes 笔记 / 任务 / 管理集群 / 用 kubeadm 管理集群 / 配置一个 cgroup 驱动
[QT] Qt project demo: data is displayed on the ui interface, double-click the mouse to display specific information in a pop-up window
window.open不显示favicon.icon
#夏日挑战赛#【FFH】OpenHarmony设备开发基础(四)启动流程
Kubernetes 笔记 / 生产环境
AI+BI+Visualization, Deep Analysis of Sugar BI Architecture
Small Tools (4) integrated Seata1.5.2 distributed transactions
设置海思芯片MMZ内存、OS内存详解
WordPress 5.2.3 更新,升级出现请求超时的解决方法
C专家编程 第3章 分析C语言的声明 3.6 typedef int x[10]和#define x int[10]的区别
测试测试测试
Leetcode76. Minimal Covering Substring
MobileVIT实战:使用MobileVIT实现图像分类
MySQL窗口函数
【QT】Qt 给已经开发好的程序快速封装成动态库
攻防世界----bug
托尔斯泰:生活中只有两种不幸
To add digital wings to education, NetEase Yunxin released the overall solution of "Internet + Education"