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

Unity, Vr, Vive - Controllers To Play / Pause a Video?

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

有谁知道如何让它在我按下触发器时暂停,然后在我再次按下它时启动?

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

}
}

这就是我使用 atm 连接控制器和 Unity 的方式。

我假设您的视频正在 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 拖放到编辑器中,应该就可以了。