Version: 2017.3

Input.acceleration

切换到手册
public static Vector3 acceleration ;

描述

最近测量的设备在三维空间中的线性加速度。(只读)

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public float speed = 10.0F; void Update() { Vector3 dir = Vector3.zero; dir.x = -Input.acceleration.y; dir.z = Input.acceleration.x; if (dir.sqrMagnitude > 1) dir.Normalize(); dir *= Time.deltaTime; transform.Translate(dir * speed); } }