Интерфейс системы ввода (Input system).
Use this class to read the axes set up in the Conventional Game Input, and to access multi-touch/accelerometer data on mobile devices.
To read an axis use Input.GetAxis with one of the following default axes:
"Horizontal" and "Vertical" are mapped to joystick, A
, W
, S
, D
and the arrow keys.
"Mouse X" and "Mouse Y" are mapped to the mouse delta.
"Fire1", "Fire2" "Fire3" are mapped to Ctrl
, Alt
, Cmd
keys and three mouse or joystick buttons.
New input axes can be added. See Input Manager for this.
If you are using input for any kind of movement behaviour use Input.GetAxis.
It gives you smoothed and configurable input that can be mapped to keyboard, joystick or mouse.
Use Input.GetButton for action like events only. Do not use it for movement. Input.GetAxis will make the script code more small and simple.
Note also that the Input flags are not reset until Update
. It is suggested you make all the Input calls in the Update
Loop.
See Also: KeyCode which lists all of the key press, mouse and joystick options.
Mobile Devices:
iOS and Android devices are capable of tracking multiple fingers touching the screen simultaneously.
You can access data on the status of each finger touching screen during the last frame by accessing the Input.touches property array.
As a device moves, its accelerometer hardware reports linear acceleration changes along the three primary axes in three-dimensional space.
You can use this data to detect both the current orientation of the device (relative to the ground) and any immediate changes to that orientation.
Acceleration along each axis is reported directly by the hardware as G-force values.
A value of 1.0 represents a load of about +1g along a given axis while a value of -1.0 represents -1g.
If you hold the device upright (with the home button at the bottom) in front of you, the X axis is positive along the right,
the Y axis is positive directly up, and the Z axis is positive pointing toward you.
You can read the Input.acceleration property to get the accelerometer reading.
You can also use the Input.deviceOrientation property to get a discrete evaluation of the device's orientation in three-dimensional space.
Detecting a change in orientation can be useful if you want to create game behaviors when the user rotates the device to hold it differently.
Note that the accelerometer hardware can be polled more than once per frame.
To access all accelerometer samples since the last frame, you can read the Input.accelerationEvents property array.
This can be useful when reconstructing player motions, feeding acceleration data into a predictor, or implementing other precise motion analysis.
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public void Update() { if (Input.GetButtonDown("Fire1")) { Debug.Log(Input.mousePosition); } } }
This component relates to legacy methods for drawing UI textures and images to the screen. You should instead use UI system. This is also unrelated to the IMGUI system.
acceleration | Последнее измеренное линейное ускорение устройства в трехмерном пространстве. (Read Only) |
accelerationEventCount | Количество измерений ускорения, произведенных за предыдущий кадр. |
accelerationEvents | Возвращает список измерений ускорения, произведенных за предыдущий кадр. (Read Only) (Выделяется память под временные переменные, т.е. в куче создаются лишние объекты). |
anyKey | Нажата ли какая-нибудь клавиша на клавиатуре или кнопка мышки? (Read Only) |
anyKeyDown | При быстром многократном нажатии клавиши клавиатуры или кнопки мыши возвращает true только в первом кадре. (Read Only) |
backButtonLeavesApp | Should Back button quit the application?Only usable on Android, Windows Phone or Windows Tablets. |
compass | Свойство для организации доступа к компасу (только для мобильных устройств). (Read Only) |
compensateSensors | Это свойство управляет компенсацией информации с сенсоров устройства, если есть необходимость компенсировать информацию в зависимости от ориентации экрана. |
compositionCursorPos | The current text input position used by IMEs to open windows. |
compositionString | The current IME composition string being typed by the user. |
deviceOrientation | Device physical orientation as reported by OS. (Read Only) |
gyro | Возвращает гироскоп по умолчанию. |
imeCompositionMode | Controls enabling and disabling of IME input composition. |
imeIsSelected | Does the user have an IME keyboard input source selected? |
inputString | Returns the keyboard input entered this frame. (Read Only) |
location | Property for accessing device location (handheld devices only). (Read Only) |
mousePosition | Текущее положение мыши в пиксельных координатах. (Read Only) |
mousePresent | Indicates if a mouse device is detected. |
mouseScrollDelta | Текущее положение мыши в пиксельных координатах. (Read Only) |
multiTouchEnabled | Property indicating whether the system handles multiple touches. |
simulateMouseWithTouches | Enables/Disables mouse simulation with touches. By default this option is enabled. |
stylusTouchSupported | Returns true when Stylus Touch is supported by a device or platform. |
touchCount | Количество касаний. Гарантируется, что количество касаний не изменится на протяжении кадра. (Read Only) |
touches | Возвращает список объектов, отражающих состояние всех касаний за последний кадр. (Read Only) (Выделяет память под временные переменные, т.е. в куче создаются лишние объекты). |
touchPressureSupported | Bool value which let's users check if touch pressure is supported. |
touchSupported | Returns whether the device on which application is currently running supports touch input. |
GetAccelerationEvent | Returns specific acceleration measurement which occurred during last frame. (Does not allocate temporary variables). |
GetAxis | Возвращает значение по axisName виртуальной оси. |
GetAxisRaw | Возвращает значение по axisName виртуальной оси без применения фильтра сглаживания. |
GetButton | Возвращает true, пока зажата кнопка buttonName. |
GetButtonDown | Возвращает true только в том кадре, в котором пользователь нажал виртуальную кнопку buttonName. |
GetButtonUp | Returns true the first frame the user releases the virtual button identified by buttonName. |
GetJoystickNames | Возвращает массив имен подключенных джойстиков. |
GetKey | Returns true while the user holds down the key identified by name. |
GetKeyDown | Возвращает true, если на протяжении кадра пользователь начинает выполнять нажатие клавиши name. |
GetKeyUp | Возвращает true, если на протяжении кадра пользователь отпустил клавишу name. |
GetMouseButton | Возвращает true, если зажата заданная кнопка мыши. |
GetMouseButtonDown | Возвращает true, если на протяжении кадра пользователь нажал заданную кнопку мыши. |
GetMouseButtonUp | Возвращает true, если на протяжении кадра пользователь отпустил заданную кнопку мыши. |
GetTouch | Call Input.GetTouch to obtain a Touch struct. |
IsJoystickPreconfigured | Determine whether a particular joystick model has been preconfigured by Unity. (Linux-only). |
ResetInputAxes | Сбрасывает весь ввод. После ResetInputAxes значения по всем осям устанавливаются равными 0 и все клавиши сбрасываются к 0 на один кадр. |