Version: 2017.3
public static float GetAxis (string axisName);

説明

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

The value will be in the range -1...1 for keyboard and joystick input. If the axis is setup to be delta mouse movement, the mouse delta is multiplied by the axis sensitivity and the range is not -1...1.

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

To set up your input or view the options for axisName, go to Edit > Project Settings > Input. This brings up the Input Manager. Expand Axis to see the list of your current inputs. You can use one of these as the axisName. To rename the input or change the positive button etc., expand one of the options, and change the name in the Name field or Positive Button field. Also, change the Type to Joystick Axis. To add a new input, add 1 to the number in the Size field.

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); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961