SteamVR 2.2.0 按键检测

using DG.Tweening;
using UnityEngine;
using Valve.VR;
using Valve.VR.InteractionSystem;

public class GameManager : MonoBehaviour
{
    public Transform Player;
    public SteamVR_Action_Boolean GrabAction;
    public SteamVR_Action_Boolean TeleportAction;
    public SteamVR_Action_Boolean TrigerAction;
    public SteamVR_Action_Vector2 TeleportAxis = SteamVR_Input.GetAction("platformer", "Move");
    public SteamVR_Action_Single TrigerAxis;
    private Hand rightHand;
    private Hand leftHand;

    private void Start()
    {
        Hand[] hands = Player.GetComponentsInChildren();
        foreach (Hand hand in hands)
        {
            if (hand.handType == SteamVR_Input_Sources.RightHand)
            {
                rightHand = hand;
            }
            else
            {
                leftHand = hand;
            }
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (GrabAction.GetStateDown(SteamVR_Input_Sources.Any))
        {
            Debug.Log("grab");
        }
        if (TeleportAction.GetState(SteamVR_Input_Sources.Any))
        {
            Vector2 teleport_axis = TeleportAxis.GetAxis(SteamVR_Input_Sources.Any);
            Debug.Log("teleport:" + teleport_axis);
        }

        if (TrigerAction.GetStateDown(SteamVR_Input_Sources.Any))
        {
             Debug.Log("triger");
        }

        if (TrigerAction.GetState(SteamVR_Input_Sources.Any))
        {
            float triger_axis = TrigerAxis.GetAxis(SteamVR_Input_Sources.Any);
            Debug.Log("triger:" + triger_axis);
        }

        if (TeleportAxis.GetState(SteamVR_Input_Sources.Any))
        {
            Vector2 teleport_axis = TeleportAxis.GetAxis(SteamVR_Input_Sources.Any);
            Debug.Log("teleport:" + teleport_axis );
        }
    }
}

SteamVR 2.2.0 按键检测_第1张图片

注意,脚本要和设置相配合,或者用TeleportAxis的方式直接指定。

你可能感兴趣的:(Unity,#,VR)