SimpleControllerVibration.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. using UnityEngine;
  10. namespace NRKernal.NRExamples
  11. {
  12. /// <summary> A simple controller vibration. </summary>
  13. public class SimpleControllerVibration : MonoBehaviour
  14. {
  15. /// <summary> The vibration time. </summary>
  16. public float vibrationTime = 0.06f;
  17. /// <summary> The vibration buttons. </summary>
  18. public ControllerButton[] vibrationButtons = { ControllerButton.TRIGGER, ControllerButton.APP, ControllerButton.HOME };
  19. /// <summary> Updates this object. </summary>
  20. void Update()
  21. {
  22. if (vibrationButtons == null || vibrationButtons.Length == 0)
  23. return;
  24. for (int i = 0; i < vibrationButtons.Length; i++)
  25. {
  26. if (NRInput.GetButtonDown(ControllerHandEnum.Right, vibrationButtons[i]))
  27. NRInput.TriggerHapticVibration(ControllerHandEnum.Right, vibrationTime);
  28. if (NRInput.GetButtonDown(ControllerHandEnum.Left, vibrationButtons[i]))
  29. NRInput.TriggerHapticVibration(ControllerHandEnum.Left, vibrationTime);
  30. }
  31. }
  32. }
  33. }