AmbientSound.cs 945 B

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