OVRAudioSourceTest.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class OVRAudioSourceTest : MonoBehaviour
  5. {
  6. public float period = 2.0f;
  7. private float nextActionTime;
  8. // Start is called before the first frame update
  9. void Start()
  10. {
  11. Material templateMaterial = GetComponent<Renderer>().material;
  12. Material newMaterial = Instantiate<Material>(templateMaterial);
  13. newMaterial.color = Color.green;
  14. GetComponent<Renderer>().material = newMaterial;
  15. nextActionTime = Time.time + period;
  16. }
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. if (Time.time > nextActionTime)
  21. {
  22. nextActionTime = Time.time + period;
  23. Material mat = GetComponent<Renderer>().material;
  24. if (mat.color == Color.green)
  25. {
  26. mat.color = Color.red;
  27. }
  28. else
  29. {
  30. mat.color = Color.green;
  31. }
  32. AudioSource audioSource = GetComponent<AudioSource>();
  33. if (audioSource == null)
  34. {
  35. Debug.LogError("Unable to find AudioSource");
  36. }
  37. else
  38. {
  39. audioSource.Play();
  40. }
  41. }
  42. }
  43. }