holopy3/Assets/SteamVR/InteractionSystem/Samples/BuggyBuddy/Audio/AmbientSound.cs

45 lines
945 B
C#
Raw Normal View History

2020-12-10 14:25:12 +00:00
using UnityEngine;
using System.Collections;
using Valve.VR;
namespace Valve.VR.InteractionSystem.Sample
{
public class AmbientSound : MonoBehaviour
{
AudioSource s;
public float fadeintime;
float t;
public bool fadeblack = false;
float vol;
// Use this for initialization
void Start()
{
AudioListener.volume = 1;
s = GetComponent<AudioSource>();
s.time = Random.Range(0, s.clip.length);
if (fadeintime > 0)
t = 0;
vol = s.volume;
SteamVR_Fade.Start(Color.black, 0);
SteamVR_Fade.Start(Color.clear, 7);
}
// Update is called once per frame
void Update()
{
if (fadeintime > 0 && t < 1)
{
t += Time.deltaTime / fadeintime;
s.volume = t * vol;
}
}
}
}