Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Input.GetAxis

マニュアルに切り替える
public static float GetAxis(string axisName);

パラメーター

説明

axisName で識別される仮想軸の値を返します

値はキーボードとジョイスティックの入力によって-1 から 1 の範囲になります。 軸がマウスの移動量で設定される場合、マウスの移動量は軸感度を乗算するので、 -1...1 の範囲ではなくなります。

これは独立したフレームレートで動作しています。よって、この関数を使った値を使用するとき、フレームレートが変更された時のことを考える必要はありません。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public float speed = 10.0F; public float rotationSpeed = 100.0F; void Update() { float translation = Input.GetAxis("Vertical") * speed; float rotation = Input.GetAxis("Horizontal") * rotationSpeed; translation *= Time.deltaTime; rotation *= Time.deltaTime; transform.Translate(0, 0, translation); transform.Rotate(0, rotation, 0); } }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public float horizontalSpeed = 2.0F; public float verticalSpeed = 2.0F; void Update() { float h = horizontalSpeed * Input.GetAxis("Mouse X"); float v = verticalSpeed * Input.GetAxis("Mouse Y"); transform.Rotate(v, h, 0); } }