C# VR单元点击保持控制器
我正在unity htc vive中制作一个游戏。我写了下面的代码,希望每当我点击并按住“触发器”按钮时,调试消息都会停止,但它们没有停止! 感谢您的帮助C# VR单元点击保持控制器,c#,unity3d,virtual-reality,C#,Unity3d,Virtual Reality,我正在unity htc vive中制作一个游戏。我写了下面的代码,希望每当我点击并按住“触发器”按钮时,调试消息都会停止,但它们没有停止! 感谢您的帮助 using System.Collections; using System.Collections.Generic; using UnityEngine; using Valve.VR; public class move : MonoBehaviour { [SteamVR_DefaultAction("Squeeze")] public
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
public class move : MonoBehaviour
{
[SteamVR_DefaultAction("Squeeze")]
public static System.Random r = new System.Random();
public float speed = 2f;
public Transform s2;
private bool ifMoving;
public SteamVR_Action_Single squeezeAction;
public SteamVR_Action_Vector2 touchPadAction;
void Awake()
{
s2 = GameObject.Find("Camera").GetComponent<Transform>();
}
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
if (SteamVR_Input._default.inActions.GrabPinch.GetStateDown(SteamVR_Input_Sources.LeftHand))
{
ifMoving = true;
}
else
{
ifMoving = false;
Debug.Log("Hej " + r.Next(1000));
}
if (ifMoving)
{
Debug.Log("Hej " + r.Next(1000));
transform.position += s2.forward * Time.deltaTime * speed;
}
}
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用Valve.VR;
公共阶级运动:单一行为
{
[SteamVR_DefaultAction(“挤压”)]
public static System.Random r=new System.Random();
公共浮动速度=2f;
公共交通;
私人住宅;
公共蒸汽泵动作单次挤压动作;
公共蒸汽行动向量2触摸板行动;
无效唤醒()
{
s2=GameObject.Find(“摄影机”).GetComponent();
}
void Start()
{
}
//每帧调用一次更新
void FixedUpdate()
{
if(streamvr\u Input.\u default.inActions.grabspinch.GetStateDown(streamvr\u Input\u Sources.LeftHand))
{
如果移动=真;
}
其他的
{
ifMoving=false;
Log(“Hej”+r.Next(1000));
}
如果(正在移动)
{
Log(“Hej”+r.Next(1000));
transform.position+=s2.forward*Time.deltaTime*速度;
}
}
}
GetStateDown()
仅对按下按钮的帧返回true
您需要使用
GetState()
,只要按下按钮,它就会返回true
。它们不会停止,因为在没有将触发器状态更改为down的每一帧中执行else
块。非常感谢。这是一个很大的帮助。