2
0

ButtonEffect.cs 869 B

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