我已尝试过此代码,但它无法正常运行:
public void carSpeed = 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;
Vector3 position = transform.position += (dir * carSpeed);
position.x = Mathf.Clamp(position.x, -2.7f, 2.7f);
transform.position = position;
}