Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class VolRamp : MonoBehaviour {
- public float rampTime = 1f; // in seconds
- private float _volume = 0f;
- private float _volumeDelta;
- void Awake () {
- AudioSource audioSource = GetComponent<AudioSource>();
- _volumeDelta = 1f / ((float)audioSource.clip.frequency * rampTime);
- }
- void OnAudioFilterRead (float[] data, int numChannels) {
- for (int i = 0; i < data.Length; ++i) {
- if (_volume < 1f) {
- _volume += _volumeDelta;
- }
- data[i] *= _volume;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement