Version: 2018.4

Input

class in UnityEngine

マニュアルに切り替える

説明

入力システムのインターフェース

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.

モバイルデバイス:

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.

Static 変数

acceleration最後に測定した 3 次元空間でのデバイスの線形加速度(読み取り専用)
accelerationEventCount最後のフレーム間で発生した測定によって得た加速度の値の数
accelerationEvents最後のフレーム間で発生した測定によって得た加速度の値(読み取り専用) (一時的な変数を割り当てます)
anyKey現在なんらかのキーかマウスボタンが押されているかどうか(読み取り専用)
anyKeyDownユーザーがなんらかのキーかマウスボタンを押した最初のフレームのみ true を返します(読み取り専用)
backButtonLeavesAppShould Back button quit the application?Only usable on Android, Windows Phone or Windows Tablets.
compassコンパスにアクセスするためのプロパティー(ハンドヘルドのみ)(読み取り専用)
compensateSensorsこのプロパティーは入力センサーが画面の向きによって補正する必要がある場合に使用します
compositionCursorPosIME で開くウィンドウに使用される現在のテキスト入力の位置
compositionString現在ユーザーによって入力されている現在の IME で構成された文字列
deviceOrientationOS によって判断されるデバイスの物理的な方向(読み取り専用)
gyroデフォルトのジャイロスコープを返します
imeCompositionModeIME 入力構成の制御の有効/無効
imeIsSelectedユーザーが選択したキーボード入力ソースが IME であるかどうか
inputString現フレームでキーボードで入力された文字を返します(読み取り専用)
locationデバイスの位置にアクセスするためのプロパティー(ハンドヘルドのデバイスのみです)(読み取り専用)
mousePosition現在のマウスの位置のピクセル座標(読み取り専用)
mousePresentIndicates if a mouse device is detected.
mouseScrollDelta現在のマウススクロールの移動量(読み取り専用)
multiTouchEnabledマルチタッチをハンドリングするかのプロパティー
simulateMouseWithTouchesEnables/Disables mouse simulation with touches. By default this option is enabled.
stylusTouchSupportedReturns true when Stylus Touch is supported by a device or platform.
touchCountタッチ数。そのフレームでは変更されないことが保証されています(読み取り専用)
touches最後のフレーム間ですべてのタッチ情報のオブジェクトリストを返します(読み取り専用) (一時的な変数を割り当てられます)
touchPressureSupportedBool value which let's users check if touch pressure is supported.
touchSupported現在実行されているアプリのデバイスがタッチ入力をサポートしているかどうか

Static 関数

GetAccelerationEvent最後のフレーム間で発生した加速度を返します(一時的な変数は割り当てられません)
GetAxis axisName で識別される仮想軸の値を返します
GetAxisRaw axisName で識別される仮想軸の平滑化フィルターが適用されていない値を返します
GetButton buttonName で識別される仮想ボタンを押している間 true を返します
GetButtonDown buttonName で識別される仮想ボタンを押したフレームの間だけ true を返します。
GetButtonUp buttonName によって識別される仮想ボタンを離したフレームの間だけ true を返します
GetJoystickNames接続されたジョイスティック名の配列を返します
GetKeyReturns true while the user holds down the key identified by name.
GetKeyDown name によって識別されるキーを押したフレームの間だけ true を返します
GetKeyUp name によって識別されるキーを離したフレームの間だけ true を返します
GetMouseButtonマウスボタンが押されているかどうかを返します
GetMouseButtonDownユーザーがマウスボタンを押したフレームの間だけ true を返します
GetMouseButtonUpマウスボタンを離したフレームの間だけ true を返します
GetTouchCall Input.GetTouch to obtain a Touch struct.
IsJoystickPreconfiguredDetermine whether a particular joystick model has been preconfigured by Unity. (Linux-only).
ResetInputAxesすべての入力をリセットします。ResetInputAxes を行った後、すべての軸は 0 になり、すべてのボタンは 1 フレームだけ 0 に戻ります