Unity中的常用输入

(1)

public static float GetAxis(string axisName);

    axisName可以为:

Horizontal 水平按键 按 A return -1~0 D 0~1

Vertical 垂直按键 按W return -1~0 S 0~1

Mouse X 判断被按鼠标在X轴上的移动方向,向右为正值

Mouse Y 判断被按鼠标在Y轴上的移动方向,向上为正值

Mouse ScrollWheel 鼠标滚轮 向上滚动为正

public static float GetAxisRaw(string axisName);与上述类似 返回值无过渡变化取值为 -1 0 1

(2)

public static bool GetButton(string buttonName);按钮被按着 返回true

public static bool GetButtonDown(string buttonName);按下按钮的那一帧 返回true

public static bool GetButtonUp(string buttonName);松开按钮那一帧 返回true

buttonName可为:

Fire1 按下鼠标左键或left+Ctrl

Fire2 按下鼠标右键或left+Alt

Fire3 按下鼠标滚轮或left+Shife

(3)

public static bool GetMouseButton(int button);

public static bool GetMouseButtonDown(int button);

public static bool GetMouseButtonUp(int button);

button可为:

0 鼠标左键按下 1 鼠标右键按下  

2 鼠标滚轮按下

(4)

public static bool GetKey(string name);

public static bool GetKeyDown(string name);

public static bool GetKeyUp(string name);

public static bool GetKey(KeyCode key);

public static bool GetKeyDown(KeyCode key);

public static bool GetKeyUp(KeyCode key);

name取值为键盘中的各种字母例如 "space"

key与name类似 使用格式为 KeyCode. Space

原文地址:https://www.cnblogs.com/unitywyb/p/12788266.html