using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;
public class HandPulse : MonoBehaviour {
private VRTK_ControllerEvents controllerEvents;
// Use this for initialization
void Start () {
var tempScript = transform.GetComponent<VRTK.VRTK_InteractableObject>();
tempScript.InteractableObjectUsed += OnInteractableObjectUsed;
tempScript.InteractableObjectUnused += OnInteractableObjectUnused;
tempScript.InteractableObjectUngrabbed += OnInteractableObjectUngrabbed;
}
// Update is called once per frame
void Update () {
if (controllerEvents)
{
float power = controllerEvents.GetTriggerAxis();
VRTK_ControllerHaptics.TriggerHapticPulse(VRTK_ControllerReference.GetControllerReference(controllerEvents.gameObject), power * 0.25f, 0.1f, 0.01f);
}
}
void OnInteractableObjectUsed(object sender, InteractableObjectEventArgs e)
{
controllerEvents = e.interactingObject.GetComponent<VRTK_ControllerEvents>();
}
void OnInteractableObjectUnused(object sender, InteractableObjectEventArgs e)
{
controllerEvents = null;
}
void OnInteractableObjectUngrabbed(object sender, InteractableObjectEventArgs e)
{
controllerEvents = null;
}
}
把脚本挂在要交互的物体上,手柄按扳机使用物体时,手柄震动,震动的强弱根据扳机按下的角度
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有