我有一个 2D 场景,它应该显示可用纸板场景列表(如缩略图)。 用户点击缩略图后,我试图将他发送到选定的纸板场景。 但是,我无法在第一个(列表)场景中捕捉到触摸事件。点击后,什么也没有发生,简单地说。 (编辑:我要补充一点,我只在 Android 上测试过)
这是我做的测试:
- I create a new project (Unity 5.0.2f) - 2D
- I put a UI button and a textfield to the scene
- 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 <<<---
- I import Google's Carboard SDK --->>> NO TOUCH EVENT WORKS! Click handler never triggered <<<---
- 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/