#游戏unity-VR场景漫游#手柄按键的触发

先给出手柄按键的大致示意图——
这里写图片描述

按键控制的脚本格式大致如下——

using UnityEngine;
using System.Collections;

public class shoubingkongzhi : MonoBehaviour {
    /// 

    /// 手柄
    /// 

    SteamVR_TrackedObject tracked;



    void Awake()
    {
        //获取手柄
        tracked = GetComponent();

    }

    // Update is called once per frame
    void FixedUpdate()
    {
        var device = SteamVR_Controller.Input((int)tracked.index);

        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Debug.Log("按下圆盘");
        }
        else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
        {

            Debug.Log("按下扳机键");
        }
        else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
        {

            Debug.Log("按下手柄侧键");
        }
        else if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
        {

            Debug.Log("按下手柄菜单键");
        }
        else if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
        {

            Debug.Log("按下手柄菜单键");
        }

    }
}

以上都是HTC VIVE手柄中按键按下的代码。其他还有:
按键松开—device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger);
按键长安—device.GetPress(SteamVR_Controller.ButtonMask.Trigger);
按键按下还有另一种方式,但是我自我感觉用着很别扭,没上述的好。device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu);
其他用法与GetPressDown()类似。

猜你喜欢

转载自blog.csdn.net/zys91011_muse/article/details/80026571
今日推荐