【问题标题】:Unity, Vr, Vive - Controllers To Play / Pause a Video?Unity、Vr、Vive - 播放/暂停视频的控制器?
【发布时间】:2018-12-18 11:04:33
【问题描述】:

我是新手,目前正在尝试让我的 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);
    }

}
}

这就是我使用 atm 来连接控制器和 Unity。

【问题讨论】:

    标签: unity3d virtual-reality htc-vive


    【解决方案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 拖放到编辑器中,它应该就是它。

    【讨论】:

    • 我目前只是在 Unity 中观看视频。所以现在统一使用播放和暂停。
    • 哈,您想暂停或播放 Unity 播放器,以便从控制器启动播放模式?
    • 标题或您的问题不是很清楚:)
    • 是的 :) 我对此很陌生。我用相机制作了一个倒置球体。我想做的是在它运行时暂停它,然后再次启动它。不确定这是否是最好的方法:)
    • 那么你有一个视频播放器正在阅读你倒置球体上播放的视频,对吗?如果是,我分享的代码适合你:)
    猜你喜欢
    • 2015-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多