Version: 5.4 (switch to 5.5b)
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.


class in UnityEngine

Suggest a change


Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.


Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.






Use this class to read the axes set up in the Input Manager, 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 in the Input Manager.

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. Don't use it for movement, Input.GetAxis will make the script code smaller and simpler.

Note also that the Input flags are not reset until "Update()", so its suggested you make all the Input Calls in the Update Loop.

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.

#pragma strict
public function Update() {
    if (Input.GetButtonDown("Fire1")) {
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public void Update() { if(Input.GetButtonDown("Fire1")) { Debug.Log(Input.mousePosition); } } }

Static Variables

acceleration最後に測定した 3 次元空間でのデバイスの線形加速度(読み取り専用)
accelerationEvents最後のフレーム間で発生した測定によって得た加速度の値(読み取り専用) (一時的な変数を割り当てます)
anyKeyDownユーザーがなんらかのキーかマウスボタンを押した最初のフレームのみ true を返します(読み取り専用)
backButtonLeavesAppShould Back button quit the application?Only usable on Android, Windows Phone or Windows Tablets.
compositionCursorPosIME で開くウィンドウに使用される現在のテキスト入力の位置
compositionString現在ユーザーによって入力されている現在の IME で構成された文字列
deviceOrientationOS によって判断されるデバイスの物理的な方向(読み取り専用)
imeCompositionModeIME 入力構成の制御の有効/無効
imeIsSelectedユーザーが選択したキーボード入力ソースが IME であるかどうか
mousePresentIndicates if a mouse device is detected.
simulateMouseWithTouchesEnables/Disables mouse simulation with touches. By default this option is enabled.
stylusTouchSupportedReturns true when Stylus Touch is supported by a device or platform.
touches最後のフレーム間ですべてのタッチ情報のオブジェクトリストを返します(読み取り専用) (一時的な変数を割り当てられます)
touchPressureSupportedBool value which let's users check if touch pressure is supported.

Static Functions

GetAxis axisName で識別される仮想軸の値を返します
GetAxisRaw axisName で識別される仮想軸の平滑化フィルターが適用されていない値を返します
GetButton buttonName で識別される仮想ボタンを押している間 true を返します
GetButtonDown buttonName で識別される仮想ボタンを押したフレームの間だけ true を返します。
GetButtonUp buttonName によって識別される仮想ボタンを離したフレームの間だけ true を返します
GetKey name によって識別されるキーを押している間、true を返します。オート射撃のようなものと考えてください
GetKeyDown name によって識別されるキーを押したフレームの間だけ true を返します
GetKeyUp name によって識別されるキーを離したフレームの間だけ true を返します
GetMouseButtonDownユーザーがマウスボタンを押したフレームの間だけ true を返します
GetMouseButtonUpマウスボタンを離したフレームの間だけ true を返します
IsJoystickPreconfiguredDetermine whether a particular joystick model has been preconfigured by Unity. (Linux-only).
ResetInputAxesすべての入力をリセットします。ResetInputAxes を行った後、すべての軸は 0 になり、すべてのボタンは 1 フレームだけ 0 に戻ります