2

我正在开发一个 Google Cardboard 项目,现在我有一个 Android 演示,您可以在其中查看我在 UNITY 3D 中构建的特殊场景,一切正常且看起来不错,但我真正想要的是:

当我按下 Google Cardboard 磁铁按钮时,我想向前走。

我在网上找到了一些脚本,但我不知道如何使这些脚本在我的 UNITY 项目中工作。

有人可以进一步帮助我吗?

4

1 回答 1

2

假设您能够正确读取磁铁输入。这就是我制作 FPS 风格控制器脚本的方式:

  1. 在 Unity5 中导入资产包 Standard Assets/Characters。
  2. 从该包中创建 RigidBodyFPSController.prefab 的实例。
  3. 删除它的子对象“MainCamera”
  4. 导入Google cardboard unitypackage
  5. 用 CardboardMain.prefab 替换您在第 3 步中删除的“MainCamera”
  6. 更新或修改 RigidbodyFirstPersonController.cs GetInput() 方法的副本。

GetInput() 与 Google Cardboard 向前移动后备:

private Vector2 GetInput()
{
    Vector2 input = new Vector2
    {
        x = Input.GetAxis("Horizontal"),
        y = Input.GetAxis("Vertical")
    };

    // If GetAxis are empty, try alternate input methods.
    if (Math.Abs(input.x) + Math.Abs(input.y) < 2 * float.Epsilon)
    {
        if (IsMoving) //IsMoving is the flag for forward movement. This is the bool that would be toggled by a click of the Google cardboard magnet
        {
            input = new Vector2(0, 1); // go straight forward by setting positive Vertical
        }
    }
    movementSettings.UpdateDesiredTargetSpeed(input);
    return input;
}

Google 的 SDK 仅支持检测磁铁“点击”。如果您想按住磁铁向前移动,我建议使用Unity3D Asset Store 中的Cardboard Controls+

于 2015-04-08T21:56:01.123 回答