Input.GetAxis

来源:互联网 发布:彩票大数据分析软件 编辑:程序博客网 时间:2024/04/30 05:02




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.
注意:Input flags只有在Update()中才会重置,所以建议大家将所有的Input 调用都放在Update循环中。
2.If you are using input for any kind of movement behaviour use Input.GetAxis. It gives you smoothed and configurable input that can be mapped to keyboard, joystick or mouse. Use Input.GetButton for action like events only. Don't use it for movement, Input.GetAxis will make the script code smaller and simpler.
如果你想使用Input制作某种运动行为,要使用Input.GetAxis方法。它能够返回来自键盘、控制器或鼠标平滑的并且可以设置的输入结果。使用Input.GetButton方法只用于像事件之类的动作。不要将它用于移动动作。Input.GetAxis方法可以使脚本代码更简洁。
3.To read an axis use Input.GetAxis with one of the following default axes: "Horizontal" and "Vertical" are mapped to joystick,A,W,S,D and the arrow keys. "Mouse X" and "Mouse Y" are mapped to the mouse delta. "Fire1", "Fire2" "Fire3" are mapped toCtrl,Alt,Cmd keys and three mouse or joystick buttons. New input axes can be added in theInput Manager.
想要读取轴向使用Input.GetAxis方法获取下列默认轴: "Horizontal" 和"Vertical" 映射于控制杆、A、W、S、D和箭头键(方向键)。 "Mouse X" 和"Mouse Y" 映射于鼠标增量,"Fire1", "Fire2" "Fire3"映射于键盘的Ctrl、Alt、Cmd键和三个鼠标键(鼠标左键,中键和右键)或控制器的按钮。新的输入轴可以使用Input Manager来添加。
4.

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

在移动设备中,手指按住屏幕移动也是鼠标增量移动

[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. if(Input.touchCount>0)  
  2. {  
  3.     if(Input.GetTouch(0).phase==TouchPhase.Moved/*&&ctrol.isGrounded*/&&!anim.IsPlaying("Jump"))  
  4.     {  
  5.         touched=true;  
  6.         if(Input.GetAxis("Mouse Y")>0.2f)  
  7.         {  
  8.   
  9.     GameManager.animstate=AnimState.jump;  
  10.     GameManager.j=0;  
  11.         }  
  12.     }  
  13. }  


手指上滑控制人物跳跃

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.






unity基础篇 输入控制

        这一篇说一下Unity3d的输入控制,在我们的游戏开发中或者是虚拟现实中,都需要相应输入的,其中输入设备包括 鼠标 摇杆等设备!

        1.InputManager

           1.1 如何打开InputManager界面

                通过 Edit-> Project Settings->Input可以打开InputManager界面!

           1.2 InputManager界面


其中,Axes(轴),下面有很多输入,Horizontal是名称,Negative Button 的值是left,Positive Button的值是right,Alt Negative Button值的是a

0 0
原创粉丝点击