我是新手,目前正在尝试让我的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之间进行连接的方式。
我认为您的视频正在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拖放到编辑器中,应该是这样。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句