- Home /
Multiple audiosources
Hi,
I have a script which needs to have multiple audio clips (sound1, sound2 etc.)
My question is as follow: Is it better to use multiple audio components or is it better to make public audioclip variables and assign those to handmade audiosources?
in case of multiple audiocomponents: How can I address the 2 audio components? Normally I would use audio.Play(); and thats it. But nnow that there are 2 audio sources, how do I say which one to pick?
in case of audioclip variables: I tried to make audioclip variables and assigning them to audio sources, but I am getting null reference exceptions. here is how I do it:
public AudioClip c_sound1; private AudioSource s_sound1;
//inside start() s_sound1.clip = c_sound1;
//when space key is pressed s_sound1.Play();
Any direction is appriciated.
Answer by uhahaha · Dec 24, 2010 at 03:24 PM
Create a AudioSource Component for your game object. The Audio Clip field may be left blank-you are trying to assign it with the script. Change the private to public. After dropping the above script to the Game Object assign c_sound & s_sound in the Inspector. Then you should have no trouble.