AmbientSound.cs 654 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. using System.Collections;
  3. using Valve.VR;
  4. public class AmbientSound : MonoBehaviour {
  5. AudioSource s;
  6. public float fadeintime;
  7. float t;
  8. public bool fadeblack = false;
  9. float vol;
  10. // Use this for initialization
  11. void Start () {
  12. AudioListener.volume = 1;
  13. s = GetComponent<AudioSource> ();
  14. s.time = Random.Range (0, s.clip.length);
  15. if (fadeintime > 0)
  16. t = 0;
  17. vol = s.volume;
  18. SteamVR_Fade.Start(Color.black, 0);
  19. SteamVR_Fade.Start(Color.clear, 7);
  20. }
  21. // Update is called once per frame
  22. void Update () {
  23. if (fadeintime > 0&&t<1) {
  24. t += Time.deltaTime / fadeintime;
  25. s.volume = t * vol;
  26. }
  27. }
  28. }