Unity之路(二):输入事件管理Input
2016-08-18 21:10
477 查看
在Unity中输入时间有Input类来管理输入事件,常用方法:
TouchPhase
输入事件需要在Update方法中处理。
示例:
print 只能在运行时类(MonoBehaviour的子类)中使用;
其他地方使用Debug.Log打印。
// 键盘事件 public static bool GetKeyDwon(enum KeyCode); // 按键按下(触发一次) public static bool GetKeyDwon(enum KeyCode); // 按键放开(触发一次) public static bool GetKey(enum KeyCode); // 持续按下(持续触发) // 鼠标事件 button:0-左键,1-右键,2-中间件 public static bool GetMouseButtonDown(int button); // 鼠标按下(触发一次) public static bool GetMouseButtonUp(int button); // 鼠标放开(触发一次) public static bool GetMouseButton(int button); // 鼠标按下(持续触发) // 触摸时间 public static int touchCount { get; }; // 触摸点个数 public static Touch GetTouch(int index); // 触摸事件
TouchPhase
Values | Description |
---|---|
Began | A finger touched the screen |
Moved | A finger moved on the screen |
Stationary | A finger is touching the screen but hasn’t moved |
Ended | A finger was lifted from the screen. This is the final phase of a touch |
Canceled | The system cancelled tracking for the touch, as when (for example) the user puts the device to her face or more than five touches happened simultaneously. This is the final phase of a touch |
示例:
void Update() { if (Input.GetKey(KeyCode.D)) { print('button d'); } if (Input.GetMouseButton(0)) { print('left'); } while (i < Input.touchCount) { if (Input.GetTouch(i).phase == TouchPhase.Began) { print(i + 'began'); } }
print 只能在运行时类(MonoBehaviour的子类)中使用;
其他地方使用Debug.Log打印。
相关文章推荐
- 关于Unity中的Input输入事件
- 【unity插件】unity手柄插件Input输入管理插件,兼容各种主流手柄
- unity中input输入事件的简单学习
- input 输入事件
- Android 2.3 input输入事件处理
- Android 4.0 事件输入(Event Input)系统
- Android 4.0 事件输入(Event Input)系统
- Android 4.0 事件输入(Event Input)系统
- Android 4.0 事件输入(Event Input)系统
- Android 4.0 事件输入(Event Input)系统
- 与众不同 windows phone (24) - Input(输入)之软键盘类型, XNA 方式启动软键盘, UIElement 的 Touch 相关事件, 触摸涂鸦
- Android input输入事件处理
- Input表单值改变(非键盘直接输入)后触发事件
- Android 4.0 事件输入(Event Input)系统
- input 输入框内的输入事件详细分析
- input子系统学习笔记九 evdev输入事件驱动分析
- Android 2.3 input输入事件处理
- Android 2.3 input输入事件处理
- input子系统学习笔记九 evdev输入事件驱动分析
- Android 4.0 事件输入(Event Input)系统