首先介绍一下unity输入设置参数所表明的含义spa
参数名 | 做用描述 |
Name 名称 | 轴的名称,用于游戏加载界面和脚本中。 |
Descriptive Name 描述 | 游戏加载界面中,轴的正向按键的详细描述。 |
Descriptive Negative Name 反向描述 |
游戏加载界面中,轴的反向按键的详细描述。 |
Negative Button 反向按钮 | 该按钮会给轴发送一个负值。 |
Alt Negative Button 备选反向按钮 | 给轴发送负值的另外一个按钮。 |
Alt Positive Button 备选正向按钮 | 给轴发送正值的另外一个按钮。 |
Gravity 重力 | 输入复位的速度,仅用于类型为 键/鼠标 的按键。 |
Dead 阈 | 任何小于该值的输入值(不论正负值)都会被视为0,用于摇杆。 |
Sensitivity灵敏度 | 对于键盘输入,该值越大则响应时间越快,该值越小则越平滑。对于鼠标输入,设置该值会对鼠标的实际移动距离按比例缩放。 |
Snap 对齐 | 若是启用该设置,当轴收到反向的输入信号时,轴的数值会当即置为0,仅用于键/鼠标 输入。 |
Invert 反转 | 启用该参数能够让正向按钮发送负值,反向按钮发送正值。 |
Type 类型 | 全部的按钮输入都应设置为 键/鼠标 (Key / Mouse) 类型,对于鼠标移动和滚轮应设为 鼠标移动(Mouse Movement)。摇杆设为摇杆轴 (Joystick Axis),用户移动窗口设为窗口移动 (Window Movement)。 |
Axis 轴 | 设备的输入轴(摇杆,鼠标,手柄等)。 |
Joy Num 摇杆编号 | 设置使用哪一个摇杆。默认是接收全部摇杆的输入。仅用于输入轴和非按键。 |
手柄在unity输入设置示意图code
左摇杆参数设置(8)blog
右摇杆参数设置(9)游戏
十字键参数设置ip
LTRT键参数设置ci
这里的左右扳机(按左键返回正值,按右键返回负值)it
设置好参数后,咱们经过代码检测到按键信息io
*如下是摇杆、十字键、和扳机键的检测设定。table
using UnityEngine; using System.Collections; public class GetInput : MonoBehaviour { void Update() { float hl = Input.GetAxis ("Horizontal_Left"); float vl = Input.GetAxis ("Vertical_Left"); float x = Input.GetAxis ("Xbox +X"); float y = Input.GetAxis ("Xbox +Y"); float hr = Input.GetAxis ("Horizontal_Right"); float vr = Input.GetAxis ("Vertical_Right"); float t = Input.GetAxis ("LRT"); if(Mathf.Abs(hl)>0.05f || Mathf.Abs(vl) > 0.05f) { print ("leftX:" + hl); print ("leftY:" + vl); } if(Mathf.Abs(x)>0.05f || Mathf.Abs(y) > 0.05f) { print ("Xbox +X:" + x); print ("Xbox +Y:" + y); } if(Mathf.Abs(hr)>0.05f || Mathf.Abs(vr) > 0.05f) { print ("RightX:" + hr); print ("RightY:" + vr); } if(Mathf.Abs(t)>0.05f) { print ("LRT:" + t); } } }
*如下是除去摇杆后的按键对应信息class
A | JoystickButton0/Joystick1Button0 |
B | JoystickButton1/Joystick1Button1 |
X | JoystickButton2/Joystick1Button2 |
Y | JoystickButton3/Joystick1Button3 |
LB | JoystickButton4/Joystick1Button4 |
RB | JoystickButton5/Joystick1Button5 |
BACK | JoystickButton6/Joystick1Button6 |
START | JoystickButton7/Joystick1Button7 |
左摇杆DOWN | JoystickButton8/Joystick1Button8 |
右摇杆DOWN | JoystickButton9/Joystick1Button9 |