手机触摸屏
Input.touchCount //手指数目
Touch touch=Input.touches[0];//获得对应手指
Touch touch = Input.GetTouch(0);//获得对应手指
touch.fingerId //手指按下时创建一个Touch对象,并分配一个fingerID
info += "deltaPosition" + touch.deltaPosition + "\n";
info += "deltaTime" + touch.deltaTime + "\n";
//手指离开屏幕并不会立即销毁Touch对象,如果是多此点击屏幕
//就会用tapCount记录次数
touch.tapCount + "\n";
//前Touch对象的状态 Begin Move Stationary Ended Cancelde
info += "Phase:" + touch.phase + "\n";
//ScreenToWorldPoint只适用于正交相机
Vector2 pos = Camera.main.ScreenToWorldPoint(touch.position);
info += "TouchPos:" + touch.position + "\n";
info += "Pos:" + pos + "\n";
电脑键盘
键盘按键:
if(Input.GetKeyDown(KeyCode.Space))
print("downdown")//键盘按键按下瞬间触发(1次)
if (Input.GetKeyUp(KeyCo