1、Mouse X 鼠标沿屏幕X移动时触发 2、Mouse Y 鼠标沿屏幕Y移动时触发 3、Mouse ScrollWheel 鼠标滚轮滚动是触发 二、键盘类 1、Vertical 键盘按上或下键时触发 2、Horizontal 键盘按左或右键时触发 返回值是一个数,正负代表方向 //获取鼠标增量,当前帧和上一帧鼠标移动的距离 Input.GetAxis ("Mouse X") ...
鼠标横向移动-1到1左 右 print(Input.GetAxis("Mouse X")); print(Input.GetAxis("Mouse Y")); 1. 2. 3. 六、其他常用方法 1、Input.GetAxisRaw() GetAxisRaw方法和GetAxis使用方法相同,不过它的返回值没有中间值,是三个固定值-1,0 ,1 2、Input.GetTouch() 2、Input.GetTouch()方法,主要用于移...
在本文中,我将会向你介绍Unity中的输入类,包括Input、KeyCode、MouseButton和Touch等。 Input类 Input类是Unity中最基础的输入类,它可以获取各种类型的输入设备的输入,例如键盘、鼠标、手柄、重力感应等。在获取输入时,我们可以使用Input类的一些方法来获取输入设备的输入状态 获取键盘按键 GetKey、GetKeyDown、GetKeyUp...
Debug.Log("Left Button Pressed");//Is middle button being pressed?if(Input.GetMouseButton(2)) Debug.Log("Middle Button Pressed");//Is right button being pressed?if(Input.GetMouseButton(1)) Debug.Log("Right Button Pressed");//Get mouse x position on screenfloatX =Input.mousePosition.x;float...
mouseScrollDelta); 4 检测键盘输入 通过Input 类检测键盘输入。 常用的方法有 Input.GetKey 检测按键是否处于按下状态 Input.GetKeyDown 检测按键是否刚刚被按下 Input.GetKeyUp 检测按键是否刚刚被松开 //键盘按下 if( Input.GetKeyDown(KeyCode.W) ) { print("W键按下"); } //传入字符串的重载 //...
重载方法:GetKeyUp (string name) (4)、GetMouseButtonDown(intbutton) 方法类型:静态。 参数:button—表示鼠标上的键,0:表示鼠标左键,1:表示鼠标右键,2表示鼠标中键,3:表示鼠标上键,4:表示鼠标下键(其中3和4件不经常用,因为有的鼠标上没有这两个键)。
说明:button 取值为 0、1、2,分别表示鼠标左键、右键、中键。 3)虚拟轴输入 在【Edit→Project Settings→Input】中可以打开 InputManager 配置界面,用户可以在此配置虚拟轴信息。 // 按左右箭头或A、D键,hor在-1~1之间变化floathor=Input.GetAxis("Horizontal");// 按上下箭头或W、S键,hor在-1~1之间变...
重载⽅法:GetKeyUp (string name) (4)、GetMouseButtonDown(intbutton) ⽅法类型:静态。 参数:button—表⽰⿏标上的键,0:表⽰⿏标左键,1:表⽰⿏标右键,2表⽰⿏标中键,3:表⽰⿏标上键,4:表⽰⿏标下键(其中3和4件不经常⽤,因为有的⿏标上没有这两个键)。
y = Input.GetAxis("Mouse X") * Time.deltaTime * speed; x = Input.GetAxis("Mouse Y") * Time.deltaTime * speed; }else{ x = y = 0 ; } //旋转角度(增加) transform.Rotate(new Vector3(x,y,0)); /**---其它旋转方式---**/ //transform.Rotate(Vector3.up *Time....
其实,在我们之前的章节案例中,我们也使用过该类获取键盘输入,例如:Input.GetKey(KeyCode.A) 就用来判断用户是否按下了字母 A 键,也就是说,GetKey方法是用来获取键盘输入的,其参数就是键盘的键值,并且这些键值也都是Unity已经提供好的常量值。接下来,我们就来看看Input类到底给我们提供了那些变量和方法。