zoukankan      html  css  js  c++  java
  • SteamVR手柄震动控制实现

    SteamVR手柄震动控制实现

    public class handCtrl : MonoBehaviour

    {

             public SteamVR_TrackedObject _TrackedObject; //定义unity中手柄控制器

             private SteamVR_Controller.Device _device;   //定义手柄控制设备

             private bool flag=false;                  //定义bool变量

            void Start()

            {

                       //确定当前手柄

                       _device = SteamVR_Controller.Input ((int)_TrackedObject.index);

            }

             //触发碰撞检测

            void OnTriggerEnter(Collider other)

             {       

                       //判断碰撞物体

                       if(other.tag.Equals("Fruit"))

                       {       

                           flag = true;

                           //调用手柄震动协同

                           StartCoroutine ("start");

                       }

             }

             //手柄震动协同

             IEnumerator start()

             {

                       //0.2秒后调用ToFalse,关闭while

                       Invoke ("ToFalse", 0.2f);

                       while (flag)

                       {

                                //震动脉冲强度

                                _device.TriggerHapticPulse (3500);

                                //等待间隔

                                yield return new WaitForEndOfFrame();

                       }

             }

             //bool转为false

             void ToFalse()

             {

                       flag = false;

             }

    }

    支持个人观看使用,如商用或转载,请告知! -----萧朗(QQ:453929789 Email:xiaolang_xl@sina.com)
  • 相关阅读:
    正则 不匹配某个单词
    希赛 系统架构设计师教程 勘误
    QQ 快速登录中获取用户信息
    requests 配置tor代理后提示'Failed to establish a new connection: [Errno -2] Name or service not known'
    xadmin choice filter 多选
    kali linux 热点 无法获取IP
    windows10 输入法添加小鹤双拼
    del: recycle for linux
    安装WSL2
    cmake(转载)
  • 原文地址:https://www.cnblogs.com/XiaoLang0/p/9554559.html
Copyright © 2011-2022 走看看