当前位置:网站首页>[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
边栏推荐
猜你喜欢
Windows 事件转发到 SQL 数据库
leetcode:189. 轮转数组
自动化部署+整合SSM项目
Hannah荣获第六季完美童模全球总决赛全球人气总冠军
How to start an NFT collection
DataGrip:非常好用的数据库工具,安装与使用教程,亮点介绍
[QT] Qt project demo: data is displayed on the ui interface, double-click the mouse to display specific information in a pop-up window
一文看懂推荐系统:召回01:基于物品的协同过滤(ItemCF),item-based Collaboration Filter的核心思想与推荐过程
C专家编程 第1章 C:穿越时空的迷雾 1.9 阅读ANSI C标准,寻找乐趣和裨益
可复现、开放科研、跨学科合作:数据驱动下的科研趋势及应用方案
随机推荐
一文看懂推荐系统:概要02:推荐系统的链路,从召回粗排,到精排,到重排,最终推荐展示给用户
MATLAB | 七夕节快到了,还不给朋友安排上这个咕呱小青蛙?
我在滴滴做开源
uniapp隐藏导航栏和横屏显示设置
spark入门学习-1
window.open does not show favicon.icon
《安富莱嵌入式周报》第276期:2022.07.25--2022.07.31
I am doing open source in Didi
B站回应HR称核心用户是Loser;微博回应宕机原因;Go 1.19 正式发布|极客头条
新版本 MaxCompute 的SQL 中支持的 EXTRACT 函数有什么作用?
【翻译】关于扩容一个百万级别用户系统的六个课程
Detailed explanation of ReentrantReadWriteLock
从零开始搭建MySQL主从复制架构
leetcode SVM
生产环境如何删除表呢?只能在SQL脚本里执行 drop table 吗
视频人脸识别和图片人脸识别的关系
Some optional strategies and usage scenarios for PWA application Service Worker caching
【无标题】
Difference and performance comparison between HAL and LL library of STM32
Web3 安全风险令人生畏?应该如何应对?