做游戏少不了控制,但是一个成熟的游戏引擎,是不能简单仅仅获取键盘中或者遥感确定的按键来控制,要考虑到用户更改游戏按键的情况,当然也得考虑到不同设备的不通输入方式,比如U3D是可以运行在iphone上的,iphone可没有键盘和上下左右键,他有平衡控制(简单化解为水平和垂直两个方向度数),如果用户使用飞行或者汽车方向盘手柄,那就不能简单用一个按键来描述了,需要有一个度数的问题(也可以简单分解为水平和垂直两个方向度数)。
U3D提供了一个Input类封装控制输入,不做详细解释,在后面我会举一些常用的例子来说明。
Class Variables
mousePositionThe current mouse position in pixel coordinates. (Read Only)
anyKeyIs any key or mouse button currently held down? (Read Only)
anyKeyDownReturns true the first frame the user hits any key or mouse button (Read Only).
inputStringReturns the keyboard input entered this frame (Read Only).
Class FunctionsGetAxis
GetAxisRaw
GetButton
GetButtonDown
GetButtonUp
GetKey
GetKeyDown
GetKeyUp
GetMouseButton
GetMouseButtonDown
GetMouseButtonUp
ResetInputAxes
---------------------------------------------------------------------------------------------------------------------------------
获取键盘某一(这里是空格键)按键状态(bool):
获取虚拟按键(这里是Jump)按键状态(bool):
获取遥感(或iphone感应)垂直轴力度(是一个0-1之间的float):
获取遥感(或iphone感应)水平轴力度(同上):
获取鼠标中键状态: