如何使用加速来移动2D游戏中的对象为Android统一?

时间:2015-08-19 18:27:24

标签: c# android unity3d

我已尝试过此代码,但它无法正常运行:

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;
}

0 个答案:

没有答案