VRTK3.3.0-002获取手柄事件

1、首先创建VRScripts空物体,用来存放脚本,在其下创建Right空物体并添加VRTK_ControllerEvents脚本

 

2、Right作为右手手柄,拖拽到[VRTK_SDKManager]的RightController上

3丶在Right上新建脚本RightController,通过得到VRTK_ControllerEvents组件注册方法,就可以监听到按下手柄哪些键了

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;//   引用VRTK命名空间

    public class RightController: MonoBehaviour
    {
    private VRTK_ControllerEvents controllerEvents;
    private void Awake()
    {
        controllerEvents = GetComponent<VRTK_ControllerEvents>();
        //  输入+=后按Tab键后自动补全方法
        controllerEvents.TouchpadPressed += ControllerEvents_TouchpadPressed;
        controllerEvents.TouchpadReleased += ControllerEvents_TouchpadReleased;
        controllerEvents.GripPressed += ControllerEvents_GripPressed;
    }

    private void ControllerEvents_GripPressed(object sender, ControllerInteractionEventArgs e)
    {
        Debug.Log("抓取键按下");
    }

    private void ControllerEvents_TouchpadReleased(object sender, ControllerInteractionEventArgs e)
    {
        Debug.Log("圆盘键按释放");
    }

    private void ControllerEvents_TouchpadPressed(object sender, ControllerInteractionEventArgs e)
    {
        Debug.Log("圆盘键按下");
    }
}

 

还有许多方法这里不逐条列出,大家自行查看VRTK_ControllerEvents脚本

4丶注意:只要涉及到操作手柄,就必须要添加VRTK_ControllerEvents脚本

转载于:https://www.cnblogs.com/myunity/p/10910025.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值