Quinhook
Quinhook

Reputation: 11

VR Unity clicking and holding controller

I'm making a game in unity htc vive. I wrote the below code and was expecting that whenever i click and hold on "trigger" button the debug messages would stop but they didn't! Any help is appreciated.

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

Upvotes: 1

Views: 1601

Answers (1)

Nicolas
Nicolas

Reputation: 479

GetStateDown()only returns true for the frame the button was pressed.

You want to use GetState() which returns trueas long as the button is pressed.

Upvotes: 1

Related Questions