Referencing Multiple AudioSources through objects

I currently have a working script that streams audio using a single audiosource.

I now want to layer some one shots over this streamed audio and I am struggling.

My current WORKING code looks somewhat like this…

var audioSource: AudioSource;
var myAudioClip: AudioClip;
var started: boolean;

//starts streaming intro music
function Start ()
	  www = new WWW ("file://" + Application.dataPath.Substring (0, Application.dataPath.LastIndexOf ("/")) + "/Assets/intro.wav"); 
	  myAudioClip = www.audioClip;
	  audioSource = GetComponent(AudioSource); = myAudioClip;
	  audioSource.loop = false;
	  started = false;

function Update()
	if(! && && !started)
		started = true;//quick reference to know audio has started

Now whilst this music plays I want to fire oneshot audio. From what I gather I should use seperate audio sources. So I created two empty gameobjects, named them AudioLeft and AudioRight and attached audiosource components to both.

I add to the start of the script…

var audioSource2: AudioSource;
var myAudioClip2: AudioClip;

and assign the myAudioClip2 with a sample loaded into memory from the unity UI.

I then tried to initialise the audio clip in the start method using

  audioSource2 = GameObject.Find("AudioLeft").GetComponent(AudioSource); = myAudioClip2;

as well as playing the clip later upon a keypress using…

      showDebugText("<b>Action:</b> Playing One Shot");;

Whilst the Playing One Shot debug text appears. It seems to be giving me an Object Reference Not Set to the Instance of an Object for the line Debug.Log(;

So for starters my assignment of audioSource2 isn’t working. I’m pretty new to all this and feel like I’ve probably made some fundamental errors so go easy on me please :slight_smile:

Thanks in advance!

Add all the audiosources to the same gameobject that the script is attached to and reference them all in the script so that you can drag each one separately into the inspector. Then you can have one continuously playing music and use the other for your “one shots”