ButtonEffect.cs 997 B

1234567891011121314151617181920212223242526272829303132333435
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. // Modified: Jingyi
  3. using UnityEngine;
  4. using System.Collections;
  5. using UnityEngine.SceneManagement;
  6. using System;
  7. namespace Valve.VR.InteractionSystem.Sample
  8. {
  9. public class ButtonEffect : MonoBehaviour
  10. {
  11. public Color buttonDownColor = Color.cyan;
  12. public Color buttonUpColor = Color.white;
  13. public void OnButtonDown(Hand fromHand)
  14. {
  15. ColorSelf(buttonDownColor);
  16. fromHand.TriggerHapticPulse(1000);
  17. }
  18. public void OnButtonUp(Hand fromHand)
  19. {
  20. ColorSelf(buttonUpColor);
  21. }
  22. private void ColorSelf(Color newColor)
  23. {
  24. Renderer[] renderers = this.GetComponentsInChildren<Renderer>();
  25. for (int rendererIndex = 0; rendererIndex < renderers.Length; rendererIndex++)
  26. {
  27. renderers[rendererIndex].material.color = newColor;
  28. }
  29. }
  30. }
  31. }