我已经使用google vr sdk创建了一个统一的vr应用程序。目前,我可以点击屏幕开始播放视频。当我使用vr耳机时,我需要使用蓝牙控制器来播放/停止视频。有人能帮我吗?
发布于 2018-02-22 18:49:46
你需要确定unity如何映射你的控制器按钮,一旦你确定了你想要按下的按钮以及unity在他的输入管理器(编辑->项目设置->输入)中如何映射,你只需要像这样从Update调用你的函数:
void Update()
{
if(Input.GetButtonUp("Fire1"))
{
playVideoFuncion();
}
}其中playVideoFunction()是您自己的函数。在本例中,我使用了"Fire1“,但在您的示例中可能有所不同。
例如,对于Xbox控制器,您可以在Xbox 360 Controller Input on Unity中解释此配置
如果你在你的控制器上找不到任何相关的东西,你可以这样做:
void Update()
{
if(Input.GetButtonUp("Fire1"))
{
Debug.Log("Fire 1 Pressed");
}
if(Input.GetButtonUp("Fire2"))
{
Debug.Log("Fire 1 Pressed");
}
if(Input.GetButtonUp("0"))
{
Debug.Log("Button 0 pressed");
}
// Add more buttons and logs
}也许还有其他方法可以识别来自随机控制器的输入,但我不知道如何识别。我需要Xbox控制器的映射,这个页面很有用。
发布于 2018-03-22 21:21:31
您可以创建一个脚本并附加到视频播放器,这样当用户单击播放器时,命令就会运行。我假设你已经有了Google VR(GVR)的unity包。添加以下示例脚本并进行修改以满足您的需要。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VideoPlayer : MonoBehaviour {
private bool _isPlaying;
// Use this for initialization
void Start () {
_isPlaying = false
}
// Update is called once per frame
void Update () {
if (GvrController.ClickButtonUp && _isPlaying) {
PlayVideo();
}
else if (GvrController.ClickButtonUp && !_isPlaying){
StopVideo ();
}
}
public void PlayVideo{
//Logic to Play Video
}
public void StopVideo{
//Logic to Stop Video
}
}https://stackoverflow.com/questions/48924019
复制相似问题