VR Unity 单击并按住控制器



我正在用unity htc vive制作一个游戏。我编写了下面的代码,并期望每当我单击并按住"触发器"按钮时,调试消息都会停止,但他们没有!任何帮助,不胜感激。

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

GetStateDown()只返回按下按钮的帧的 true。

您希望使用只要按下按钮就会返回true GetState()

最新更新