返回由 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); } }