1.Note also that the Input flags are not reset until "Update()", so its suggested you make all the Input Calls in the Update Loop.
A
,
W
,
S
,
D
and the arrow keys. "Mouse X" and "Mouse Y" are mapped to the mouse delta. "Fire1", "Fire2" "Fire3" are mapped to
Ctrl
,
Alt
,
Cmd
keys and three mouse or joystick buttons. New input axes can be added in the
Input Manager.
Details
All the axes that you set up in the Input Manager serve two purposes:在Input Manager中设置的轴有2个目的:
- They allow you to reference your inputs by axis name in scripting让你可以在脚本中通过轴的名称来使用Input。
- They allow the players of your game to customize the controls to their liking让游戏玩家可以自定义游戏的输入。
All defined axes will be presented to the player in the game launcher, where they will see its name, detailed description, and default buttons. From here, they will have the option to change any of the buttons defined in the axes. Therefore, it is best to write your scripts making use of axes instead of individual buttons, as the player may want to customize the buttons for your game.
还是建议使用Input.GetAxis,因为使用GetAxis的功能,我们可以在定义游戏加载的时候自定义它们的按键(在standalone平台中,进入游戏前弹出一个窗口,可以选择Graphics(包括分辨率和图形质量)和Input),如果使用GetButton等就不能够使用户自定义了。当然,轴不适合定义一些隐藏或秘密功能,因为它会在加载界面中清楚地显示给玩家。
5.
Using Input Axes from Scripts
You can query the current state from a script like this:
value = Input.GetAxis ("Horizontal"); 按下左右方向键,或a、d键,value会由0渐变为1或-1,渐变的时间由sensitivity决定。不按的话该值为0。这种情况用于操纵杆输入和键盘输入。
An axis has a value between -1 and 1. The neutral position is 0. This is the case for joystick input and keyboard input.
However, Mouse Delta and Window Shake Delta are how much the mouse or window moved during the last frame. This means it can be larger than 1 or smaller than -1 when the user moves the mouse quickly.然而,鼠标增量和Window Shake增量是鼠标或窗口从上一帧到现在的移动。这意思是当用户快速移动鼠标时,它可能大于1或小于-1。
鼠标增量移动:Input.GetAxis("Mouse X")或Input.GetAxis("Mouse Y"),值为一帧内实际的鼠标移动增量乘以sensitivity
在移动设备中,手指按住屏幕移动也是鼠标增量移动
if(Input.touchCount>0)
{
if(Input.GetTouch(0).phase==TouchPhase.Moved/*&&ctrol.isGrounded*/&&!anim.IsPlaying("Jump"))
{
touched=true;
if(Input.GetAxis("Mouse Y")>0.2f)
{
GameManager.animstate=AnimState.jump;
GameManager.j=0;
}
}
}
手指上滑控制人物跳跃
It is possible to create multiple axes with the same name. When getting the input axis, the axis with the largest absolute value will be returned. This makes it possible to assign more than one input device to one axis name. For example, create one axis for keyboard input and one axis for joystick input with the same name. If the user is using the joystick, input will come from the joystick, otherwise input will come from the keyboard. This way you don't have to consider where the input comes from when writing scripts.
可以创建具有相同名称的多个轴。当获取输入轴时,带有最大绝对值的轴将被返回。这使得分配多个输入设备为一个相同的轴名成为可能。例如,创建一个轴为键盘输入,一个轴为操纵杆输入,具有相同的名称。如果用户使用操纵杆,输入将来自操纵杆,否则输入将来自键盘。这样,当写脚本时就不必考虑输入来自什么设备了。
6.Input.GetAxis():This is frame-rate independent; you do not need to be concerned about varying frame-rates when using this value.