public static Vector3 mousePosition { get; }
摘要:The current mouse position in pixel coordinates. (Read Only)
当前鼠标位置的像素坐标。(只读)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestInput : MonoBehaviour
{
void Update()
{
Debug.Log(Input.mousePosition);
}
}
public static bool anyKey { get; }
摘要:Is any key or mouse button currently held down? (Read Only)
当前是否有任何键或鼠标按钮被按住?(只读)
有任意键按住为True,否则为False
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestInput : MonoBehaviour
{
void Update()
{
Debug.Log(Input.anyKey);
}
}
public static bool anyKeyDown { get; }
摘要:Returns true the first frame the user hits any key or mouse button. (Read Only)
当用户点击任意键或鼠标按钮时,返回true。(只读)
与anyKey区别:anyKey在任意键按住时不松手会一直触发,直到松手时不再触发。anyKeyDown只在按下时触发一次,之后不松手也不会再触发,直到再次检测到按下。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestInput : MonoBehaviour
{
void Update()
{
Debug.Log(Input.anyKeyDown);
}
}
public static string inputString { get; }
摘要:Returns the keyboard input entered this frame. (Read Only)
返回输入到此帧的键盘输入。(只读)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestInput : MonoBehaviour
{
void Update()
{
if (Input.inputString.Length>0)
{
Debug.Log(Input.inputString);
}
}
}
public static float GetAxis(string axisName);
摘要:Returns the value of the virtual axis identified by axisName.
返回由axisName标识的虚拟轴的值。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestInput : MonoBehaviour
{
void Update()
{
//Debug.Log(Input.GetAxis("Horizontal"));//按下左右键或AD键,输出为-1到1,正负代表方向
//Debug.Log(Input.GetAxis("Vertical"));//按下上下键或WS键(输出为-1到1)
//Debug.Log(Input.GetAxis("Mouse X"));//此帧中鼠标在X方向上相对上一帧的偏移量
//Debug.Log(Input.GetAxis("Mouse Y"));//此帧中鼠标在Y方向上相对上一帧的偏移量
//Debug.Log(Input.GetAxis("Mouse ScrollWheel")); //此帧中鼠标滚轮相对上一帧的偏移量
}
}
public static float GetAxisRaw(string axisName);
摘要:Returns the value of the virtual axis identified by axisName with no smoothing filtering applied.
返回不应用平滑滤波的axisName标识的虚拟轴的值。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestInput : MonoBehaviour
{
void Update()
{
//Debug.Log(Input.GetAxisRaw("Horizontal"));//按下左右键或AD键,输出只有-1或1,正负代表方向
//Debug.Log(Input.GetAxisRaw("Vertical"));//按下上下键或WS键,输出只有-1或1
//Debug.Log(Input.GetAxisRaw("Mouse X"));//此帧中鼠标在X方向上相对上一帧的偏移量
//Debug.Log(Input.GetAxisRaw("Mouse Y"));//此帧中鼠标在Y方向上相对上一帧的偏移量
//Debug.Log(Input.GetAxisRaw("Mouse ScrollWheel")); //此帧中鼠标滚轮相对上一帧的偏移量
//Debug.Log(Input.GetAxisRaw("Jump"));//按下空格键输出1
}
}
public static bool GetButton(string buttonName);
摘要:Returns true while the virtual button identified by buttonName is held down.
当按下buttonName标识的虚拟按钮时,返回true。
public static bool GetButtonDown(string buttonName);
摘要:Returns true during the frame the user pressed down the virtual button identified by buttonName.
在用户按下buttonName标识的虚拟按钮的帧期间返回true。
public static bool GetButtonUp(string buttonName);
摘要: Returns true the first frame the user releases the virtual button identified by buttonName.
当用户释放第一个由buttonName标识的虚拟按钮时,返回true。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestInput : MonoBehaviour
{
void Update()
{
if (Input.GetButton("Fire1"))//按住鼠标左键
{
Debug.Log("Fire1按住");
}
if (Input.GetButtonDown("Fire1"))//按下鼠标左键
{
Debug.Log("Fire1按下");
}
if (Input.GetButtonUp("Fire1"))//抬起鼠标左键
{
Debug.Log("Fire1抬起");
}
}
}
public static bool GetKey(string name);
摘要:Returns true while the user holds down the key identified by name.
当用户按下按名称标识的键时,返回true。
public static bool GetKey(KeyCode key);
摘要:Returns true while the user holds down the key identified by the key KeyCode enum parameter.
当用户按住key KeyCode enum参数标识的键时,返回true。
public static bool GetKeyDown(KeyCode key);
摘要:Returns true during the frame the user starts pressing down the key identified by the key KeyCode enum parameter.
在帧期间返回true,用户开始按下key KeyCode enum参数标识的键。
public static bool GetKeyDown(string name);
摘要:Returns true during the frame the user starts pressing down the key identified by name.
在帧期间返回true,用户开始按下按名称标识的键。
public static bool GetKeyUp(KeyCode key);
摘要:Returns true during the frame the user releases the key identified by the key KeyCode enum parameter.
在帧期间返回true,用户释放key KeyCode enum参数标识的键。
public static bool GetKeyUp(string name);
摘要:Returns true during the frame the user releases the key identified by name.
在帧期间返回true,用户释放按名称标识的键。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestInput : MonoBehaviour
{
void Update()
{
if (Input.GetKeyDown("a"))
{
Debug.Log("A键按下");
}
if (Input.GetKeyDown(KeyCode.B))
{
Debug.Log("按下B键");
}
if (Input.GetKey("c"))
{
Debug.Log("C键按住");
}
if (Input.GetKey(KeyCode.D))
{
Debug.Log("按住D键");
}
if (Input.GetKeyUp("space"))
{
Debug.Log("空格键抬起");
}
if (Input.GetKey(KeyCode.Space))
{
Debug.Log("抬起空格键");
}
}
}
参数参考表:https://blog.csdn.net/qq_21397217/article/details/84859320
// 辅助键
"left shift", "right shift",
"left ctrl", "right ctrl",
"left alt", "right alt",
// 空格键
"space",
// 方向键
"up", "down", "right", "left",
// 取消键
"escape",
// f1~f15键
"f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8",
"f9", "f10", "f11", "f12", "f13", "f14", "f15",
// 数字键
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
// 字母键
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
// 符号键(没有 “~” 和 “%”)
"`", "!", "@", "#", "$", "^", "&", "*", "(", ")", "-", "_", "=", "+",
"[", "]", "\\", ";", ":", "'", "\"", ",", "<", ".", ">", "/", "?",
// 编辑键
"tab", "backspace", "delete",
"home", "end", "insert",
"page up", "page down",
// 锁定键
"caps lock",
"numlock",
"scroll lock",
// 其他键
"pause", "clear", "return",
public static bool GetMouseButtonDown(int button);
摘要:Returns true during the frame the user pressed the given mouse button.
在用户按下给定的鼠标按钮的帧期间返回true。
public static bool GetMouseButton(int button);
摘要:Returns whether the given mouse button is held down.
返回是否按下给定的鼠标按钮。
public static bool GetMouseButtonUp(int button);
摘要: Returns true during the frame the user releases the given mouse button.
在帧期间返回true,用户释放给定的鼠标按钮。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestInput : MonoBehaviour
{
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log("按下鼠标左键");
}
if (Input.GetMouseButton(1))
{
Debug.Log("按住鼠标右键");
}
if (Input.GetMouseButtonUp(2))
{
Debug.Log("抬起鼠标滚轮");
}
}
}
public static bool simulateMouseWithTouches { get; set; }
摘要:Enables/Disables mouse simulation with touches. By default this option is enabled. 启用/禁用使用触摸模拟鼠标操作。默认情况下启用此选项。
public static Vector3 acceleration { get; }
摘要:Last measured linear acceleration of a device in three-dimensional space. (Read Only)最后在三维空间测量了一个装置的线性加速度。(只读)
public static AccelerationEvent[] accelerationEvents { get; }
摘要:Returns list of acceleration measurements which occurred during the last frame.(Read Only) (Allocates temporary variables). 返回上一帧中发生的加速度测量值列表。(只读)(分配临时变量)。/在上一帧期间Unity引擎采集到的所有重力加速器信息(每个方向上的加速度和时间增量)
public static int accelerationEventCount { get; }
摘要:Number of acceleration measurements which occurred during last frame. 在上一帧中发生的加速度测量次数。
public static bool multiTouchEnabled { get; set; }
摘要: Property indicating whether the system handles multiple touches.指示系统是否处理多点触摸。
public static Touch[] touches { get; }
摘要:Returns list of objects representing status of all touches during last frame.(Read Only) (Allocates temporary variables).
返回表示上一帧中所有触摸状态的对象列表。(只读)(分配临时变量)。/在上一帧中的触摸点(Touch)信息
public static int touchCount { get; }
摘要:Number of touches. Guaranteed not to change throughout the frame. (Read Only) 在此帧中的触摸数量(只读)
public static bool mousePresent { get; }
摘要:Indicates if a mouse device is detected. 指示是否检测到鼠标设备。
public static bool stylusTouchSupported { get; }
摘要:Returns true when Stylus Touch is supported by a device or platform. 当设备或平台支持手写笔触摸时,返回true。
public static bool touchSupported { get; }
摘要:Returns whether the device on which application is currently running supports touch input. 返回当前运行应用程序的设备是否支持触摸输入。
Touch结构体 | 摘要 | 说明 |
fingerId | The unique index for the touch. | 触摸的唯一索引。 |
position | The position of the touch in pixel coordinates. | 触摸在像素坐标中的位置。 |
rawPosition | The raw position used for the touch. | 用于触摸的原始位置。 |
deltaPosition | The position delta since last change. | 上次改变后的位置。 |
deltaTime | Amount of time that has passed since the last recorded change in Touch values. | 上次记录的触摸值变化后经过的时间。 |
tapCount | Number of taps. | 敲击的数量。 |
phase | Describes the phase of the touch. | 描述触摸的阶段。 |
pressure | The current amount of pressure being applied to a touch. 1.0f is considered to be the pressure of an average touch. If Input.touchPressureSupported returns false, the value of this property will always be 1.0f. | 当前施加在触摸上的压力。1.0f被认为是平均触摸的压力。如果输入。touchPressureSupported返回false,此属性的值将始终为1.0f。 |
maximumPossiblePressure | The maximum possible pressure value for a platform. If Input.touchPressureSupported returns false, the value of this property will always be 1.0f. | 平台可能的最大压力值。如果输入。touchPressureSupported返回false,此属性的值将始终为1.0f。 |
type | A value that indicates whether a touch was of Direct, Indirect (or remote), or Stylus type. | 指示触摸是直接、间接(或远程)或手写笔类型的值。 |
altitudeAngle | Value of 0 radians indicates that the stylus is parallel to the surface, pi/2 indicates that it is perpendicular. | |
azimuthAngle | Value of 0 radians indicates that the stylus is pointed along the x-axis of the device. | |
radius | An estimated value of the radius of a touch. Add radiusVariance to get the maximum touch size, subtract it to get the minimum touch size. | 触摸半径的估计值。添加radiusVariance得到最大的触摸尺寸,减去它得到最小的触摸尺寸。 |
radiusVariance | The amount that the radius varies by for a touch. | 触摸半径的变化量。 |
TouchPhase枚举 | 说明 |
Began | 一根手指触到了屏幕。 |
Moved | 一根手指在屏幕上移动。 |
Stationary | 一根手指正在触摸屏幕,但没有移动。 |
Ended | 一根手指从屏幕上抬了起来。这是触摸的最后阶段。 |
Canceled | 系统取消了对触摸的跟踪。 |
TouchType枚举 | 说明 |
Direct | 直接触摸设备。 |
Indirect | 间接或远程触摸设备。 |
Stylus | 触控笔在设备上的触控。 |