Unity,Vr,Vive-播放/暂停视频的控制器?

时间:2018-12-18 11:04:33

标签: unity3d virtual-reality htc-vive

我是新手,目前正在尝试让我的Vive控制器暂停/播放Unity。到目前为止,我可以看到我的“手”,并且它确实能够识别我的触发器,而这正是它所需要的。

有人知道如何在按下触发器时使它暂停,然后在再次按下它时启动吗?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;

public class Viveinput : MonoBehaviour
{
[SteamVR_DefaultAction("Squeeze")]
public SteamVR_Action_Single squeezeAction;
public bool paused;

void Update () {
    if (SteamVR_Input._default.inActions.GrabPinch.GetLastStateUp(SteamVR_Input_Sources.Any))
    {
        print(" Grab Pinch Up");
    }
    float triggerValue = squeezeAction.GetAxis(SteamVR_Input_Sources.Any);

    if (triggerValue > 00f)
    {
        print(triggerValue);
    }

}
}

这就是我在控制器和Unity之间使用atm进行连接的方式。

1 个答案:

答案 0 :(得分:1)

我认为您的视频正在VideoPlayer MonoBehaviour上播放:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;

public class Viveinput : MonoBehaviour
{
public VideoPlayer video;

[SteamVR_DefaultAction("Squeeze")]
public SteamVR_Action_Single squeezeAction;
private bool _triggered = false;

void Update () {
    if (SteamVR_Input._default.inActions.GrabPinch.GetLastStateUp(SteamVR_Input_Sources.Any))
    {
        print(" Grab Pinch Up");
    }
    float triggerValue = squeezeAction.GetAxis(SteamVR_Input_Sources.Any);

    if (triggerValue > 0f && !_triggered)
    {
        _triggered = true; // This will prevent the following code to be executed each frames when pressing the trigger.
        if(!video.isPlaying) { // You dont need a paused boolean as the videoplayer has a property for that.
            video.Play();
        } else {
            video.Pause();
        }
    } else {
         _triggered = false;
    }    
}
}

您需要将VideoPlayer拖放到编辑器中,并且应该是它。