SteamVR手柄震动应用方法
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HapticPulseClass
{
SteamVR_TrackedObject Hand;
SteamVR_Controller.Device Device;
bool flag = false;
void Start()
{
Hand = GetComponentInParent<SteamVR_TrackedObject>();
Device = SteamVR_Controller.Input((int)Hand.index);
vodi OnTriggerEnter(Collider other)
{
if(other.tag == "Diglett")
flag = true;
StartCoroutine(HapticPulse());
}
//触发震动的条件
IENumerator HpaticPulse()
{
while(flag)
{
Invoke("StopHapticPulse",1);
Device.TriggerHapticPulse(3000);
//等待帧结束执行,等待所有的摄像机和GUI渲染接受后渲染(在屏幕显示之前)
yield return new WaitForEndOfFrame();
}
}
void StopHapticPulse()
{
flag = false;
}
}
}