BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / VR / Scripts / Util / OVRAudioSourceTest.cs

OVRAudioSourceTest.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
OVRAudioSourceTest.cs 1.0 KiB Download Raw
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4
5public 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}