Can I play multiple AudioSources from one gameobject?

I've searched and read many different posts and still haven't been able to accomplish this. Ideally I'd like to attach several different AudioSource components to a game object and be able to trigger them from a script attached to that object.

I've tried several different things and no matter which method I try, there seems to be a different issue keeping me from being able to play the sounds properly.

1- I want to be able to set some sounds to loop and others to not loop. Because of this, I need to create Audio Sources and not just use audio.PlayOneShot or AudioSource.PlayClipAtPoint. (Not to mention that I want to be able to set other parameters easily, such as the 3D settings and priority, volume and pitch.)

2- I need all of the sounds to be 3D positioned on the game object, so creating a game object for each sound and calling them in the script using TireRollLoop.Play(); for example, will not work, as the sounds are tied to their own game object's position in the scene.

3- Using audio.clip = TireRollLoop; to set the sound and then playing the sound using audio.Play() does not work because I need to be able to play some sounds at the same time.

Sorry for the lengthy question but I've been running into all sorts of issues. I am not a programmer but can usually make things work by trial and error.

This is already answered but one more thing left: with drag and drop of audioclip (as you could see in unity video tutorials) you can assign only one audiosource for a gameobject. If you drag and drop second audioclip - second audiosource will not be created and just clip will be changed in audiosource reference. So for adding next one audiosource for same gameobject you have to choose AddComponent->Audio->AudioSource

// you can then access the different AudioSources using the variables you've set:

audio2.Play();
audio1.Stop();

NOTE: Presently, the AudioSources are added to the array in the order they appear in the Inspector, as we could expect. Unfortunately, nobody knows if this order may be different in future Unity versions. If you want to be sure about that, you can set different Priority values (for instance) and check them in Start.

This is GREAT!!! You've helped me with a couple questions on this site and I really appreciate it! It works perfectly! The other path I was going down was to create a game object for every sound and then have the sound's game object follow the game object I want it positioned to. This is a much better solution! My next issue is going to be randomizing audio using an array and I'm wondering how this will work since I'm already using an array but I'll cross that bridge when I get there. Thanks again! Here's what I did to test it:

I noticed that I didn't have to set the audio source variables on the script in the inspector. As a test, I commented out the three variables from the script and it doesn't look like I need them since the sounds still play.

It looks like all I have to do is create the audio source components and assign them each a clip, create the array of different audio sources in the script, then call the audio source I want to play.

When you removed the variable declaration, the compiler created the variables itself inside Start. The problem here is that these variables are temporary: they die as soon as you leave the function. You can't use them in Update, for instance; the compiler may even create the variables inside Update, but they will be brand new instances, and you will have a Null Reference error when trying to use them.

You! I don't know why this concept is SO HARD to remember for having multiples of things... Thank you for being the only person to remind me after an hour of searching! When in doubt?? Add it in the inspector! Thanks!

only thing is you need to have GameObject created with AudioSource on it and add to the public spot. doing it this way allows me not to use as much coding and can add as many sounds as i like to play i'm just not sure how much space would be needed this way if its more or less than other way i know using AudioClip.