我正在开发一个 Google Cardboard 项目,现在我有一个 Android 演示,您可以在其中查看我在 UNITY 3D 中构建的特殊场景,一切正常且看起来不错,但我真正想要的是:
当我按下 Google Cardboard 磁铁按钮时,我想向前走。
我在网上找到了一些脚本,但我不知道如何使这些脚本在我的 UNITY 项目中工作。
有人可以进一步帮助我吗?
我正在开发一个 Google Cardboard 项目,现在我有一个 Android 演示,您可以在其中查看我在 UNITY 3D 中构建的特殊场景,一切正常且看起来不错,但我真正想要的是:
当我按下 Google Cardboard 磁铁按钮时,我想向前走。
我在网上找到了一些脚本,但我不知道如何使这些脚本在我的 UNITY 项目中工作。
有人可以进一步帮助我吗?
假设您能够正确读取磁铁输入。这就是我制作 FPS 风格控制器脚本的方式:
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+。