40 lines
915 B
C#
40 lines
915 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
|
|
public class hapticInteractable : MonoBehaviour
|
|
{
|
|
[Range(0,1)]
|
|
public float intensity;
|
|
public float duration;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
}
|
|
|
|
public void TriggerHaptic(BaseInteractionEventArgs eventArgs)
|
|
{
|
|
if(eventArgs.interactorObject is XRBaseControllerInteractor controllerInteractor)
|
|
{
|
|
TriggerHaptic(controllerInteractor.xrController);
|
|
}
|
|
|
|
}
|
|
|
|
public void TriggerHaptic(XRBaseController controller)
|
|
{
|
|
if(intensity>0)
|
|
controller.SendHapticImpulse(intensity, duration);
|
|
}
|
|
|
|
public void vibrate(float value)
|
|
{
|
|
Debug.Log("Wert: " + value);
|
|
if(intensity>0)
|
|
gameObject.GetComponent<XRBaseController>().SendHapticImpulse(intensity, value);
|
|
}
|
|
|
|
|
|
}
|