Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.0 KiB

  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. }