android - 在 Unity 5 中使用 Cardboard SDK - 没有触摸事件?

标签 android unity3d google-cardboard

我有一个 2D 场景,它应该显示可用纸板场景列表(如缩略图)。 用户点击缩略图后,我试图将他发送到选定的纸板场景。 但是,我无法在第一个(列表)场景中捕捉到触摸事件。点击后,什么也没有发生,简单地说。 (编辑:我要补充一点,我只在 Android 上测试过)

这是我做的测试:

  1. I create a new project (Unity 5.0.2f) - 2D
  2. I put a UI button and a textfield to the scene
  3. I add a script that is triggered after clicking the button - it just changes the text of the textfield to "Clicked" --->>> ALL WORKS FINE, tapping the button on the touch screen works as expected, text changed <<<---
  4. I import Google's Carboard SDK --->>> NO TOUCH EVENT WORKS! Click handler never triggered <<<---
  5. I delete Google's Cardboard SDK --->>> TAPS WORK AGAIN <<<---

触发点击的脚本很简单:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TestScript : MonoBehaviour {

    public Text text;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }

    public void ButtonClicked() {
        text.text = "Clicked!";
//      Application.LoadLevel ("DemoScene");
    }
}

所以基本上完​​全导入 Cardboard SDK 会破坏 Unity 5 中的触摸事件。如果我直接在 unity 中测试它,鼠标事件工作正常。即使导入了 Cardboard SDK,文本也会发生变化。有人知道吗?我做错了什么还是 Unity 错误?

最佳答案

另一种方法,假设您想要保留 TapIsTrigger/想要在 VR 模式下使用此 2D 场景,请使用:

if(Cardboard.SDK.CardboardTriggered){
    //what you want to happen when the user touches the screen
}

同样,您需要勾选 TapIsTrigger 才能正常工作。

关于android - 在 Unity 5 中使用 Cardboard SDK - 没有触摸事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30387721/

相关文章:

c# - 如何使用 C# 在 Unity 中截取我的桌面应用程序的当前 View 的屏幕截图?

android - 如何使用 AChartEngine 将图表高度设置为接近底部?

java - 如何从普通 java 类重定向到其他扩展 android 中 Activity 的 java 类?

c# - 应遵循另一个 GameObject 位置的脚本的问题

android - 将触摸事件添加到 google cardboard SDK for android 的 VrPanoramaView 类

c# - Unity 构建太大的立方体贴图

android - 如何获取在 ContextMenu 上单击的 Item 的位置?

android - 为什么当我使用 setClickable(true) 它不显示点击 Action

c# - 将字符串解析为 Unity3D 中的代码 (C#)