Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.52 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Music : MonoBehaviour {
  5.  
  6.     public AudioSource audioPlayer;
  7.     public ScreenManager sManager;
  8.  
  9.    
  10.     void Start ()
  11.     {
  12.         audioPlayer = GetComponent<AudioSource> ();
  13.     }
  14.  
  15.     void Update ()
  16.     {
  17.  
  18.     }
  19.  
  20.     void CrossFadeMusic(AudioSource a1, AudioSource a2, float duration)
  21.     {
  22.         float v0 = a1.volume;
  23.         a2.Play ();
  24.         float t = 0;
  25.  
  26.         if (t < 1)
  27.         {
  28.             t = Mathf.Clamp01(t + Time.deltaTime / duration);
  29.             a1.volume = (1 - t) * v0;
  30.             a2.volume = t * v0;
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement