当先锋百科网

首页 1 2 3 4 5 6 7
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<SteamVR_Action_Vector2>("platformer", "Move");
    public SteamVR_Action_Single TrigerAxis;
    private Hand rightHand;
    private Hand leftHand;

    private void Start()
    {
        Hand[] hands = Player.GetComponentsInChildren<Hand>();
        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 );
        }
    }
}

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