using UnityEngine; using System.Collections; public class musicController : MonoBehaviour { public AudioClip startMusic; public AudioClip endMusic; private AudioSource source; private bool triggered = false; void Awake(){ source = GetComponent (); } // Use this for initialization void Start () { source.clip = startMusic; } // Update is called once per frame void Update () { if (Input.GetKeyDown (KeyCode.Equals)) { source.volume += 0.1f; } if (Input.GetKeyDown (KeyCode.Minus)) { source.volume -= 0.1f; } } IEnumerator fadeOut (float end, float steps){ Debug.Log ("Volume: " + source.volume); float curVol = source.volume; while(source.volume > end + steps) { source.volume -= steps * Time.deltaTime; Debug.Log ("Volume: " + source.volume); yield return new WaitForSeconds(0.01f); } source.volume = end; source.clip = endMusic; source.Play(); StartCoroutine (fadeIn (curVol, 0.2f)); yield return null; } IEnumerator fadeIn (float end, float steps){ while(source.volume