磁铁脚本UNITY 3D [英] Magnet script for UNITY 3D

查看:1144
本文介绍了磁铁脚本UNITY 3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个谷歌纸板项目,现在我有一个演示的Andr​​oid其中u可以在一个特殊的场景我打造UNITY 3D环顾四周,一切工作正常和放大器;看起来不错,但我真正想要的是:

I'm working on a Google Cardboard project, right now i have a demo for Android where u can look around in a special scene i build in UNITY 3D, everything is working fine & looking good, but what I really want is:

我要向前走的时候我preSS的谷歌纸板磁铁按钮。

I want to walk forward when I press the Google Cardboard magnet button.

我发现了几个剧本是在网络上,但我不知道如何让这些脚本在我的UNITY项目工作。

I found a few script's on the web, but I do not know exactly how to make these scripts work in my UNITY project.

任何人都可以帮我这个吗?

Can anybody help me further with this?

推荐答案

假设你能够正确读取磁铁投入。这是我做了一个FPS风格的控制器脚本:

Assuming you are able to read the magnet input correctly. This is how I did an FPS style controller script:

  1. 在Unity5导入资产包标准资产/字符。
  2. 创建的从包RigidBodyFPSController。prefab一个实例。
  3. 删除它的子对象,MainCamera
  4. 导入谷歌纸板unitypackage
  5. 替换MainCamera你在步骤#3除去CardboardMain。prefab
  6. 在更新或修改RigidbodyFirstPersonController.cs GetInput的副本()方法。
  1. In Unity5 import the asset package Standard Assets/Characters.
  2. Create an instance of RigidBodyFPSController.prefab from that package.
  3. Remove it's child object, "MainCamera"
  4. Import the Google cardboard unitypackage.
  5. Replace the "MainCamera" you removed in step #3 with CardboardMain.prefab
  6. Update or modify a copy of RigidbodyFirstPersonController.cs GetInput() method.

GetInput()与谷歌纸板前进后退:

GetInput() with Google Cardboard forward movement fallback:

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

谷歌的SDK唯一支持的检测磁铁点击。如果你想按住磁铁向前走,我建议使用纸板控制+ 从Unity3D资源商店。

Google's SDK only support's detecting a magnet "click". If you want to hold down the magnet to move forward, I recommend using Cardboard Controls+ from the Unity3D Asset Store.

这篇关于磁铁脚本UNITY 3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆