Change Audio Clip at Runtime according Levels

 

Create a new Empty Object

name it DontDestroy because it persists as many levels loaded

attach the following script for not destroying

   1: void Awake () {
   2:     DontDestroyOnLoad(gameObject);
   3:     }

Then make a new script for audioClip changing


It will also attaches with the same Object as above.



   1:  
   2:     public AudioClip level2Music;
   3:  
   4:     private AudioSource source;
   5:     // Use this for initialization
   6:     void Awake ()
   7:     {
   8:         source = GetComponent<AudioSource>();
   9:     }
  10:     
  11:     // Update is called once per frame
  12:     void OnLevelWasLoaded(int level)
  13:     {
  14:         if (level==1)
  15:         {
  16:             source.clip = level2Music;
  17:             source.Play();
  18:         }
  19:     }

and that’s it Run in the editor and Enjoy :)

Comments

  1. The snow Peak Titanium Flask | TITanium-Arts
    The snow titanium necklace Peak Titanium titanium stud earrings Flask. 5 kg. A shovel in seiko titanium a pot. A shovel in titanium helix earrings a pot. A titanium knife shovel in a pot. A shovel in a pot.

    ReplyDelete

Post a Comment