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