audio

Im assigning various audio clips like:

var audio1 : AudioClip;
var audio2 : AudioClip;

How can I get each one to play?

In addition, you’ll need an AudioSource in order to play the clips. Attach an AudioSource behavior to the some GameObject that has your script attached, then in your script, you should be able to do something like this:

function YourSoundPlayingFunction() {
   audio.Play(audio1);
}

Then it’s just a matter of calling “YourSoundPlayingFunction()” when you want the sound to fire, or if you prefer, calling “audio.Play(audio1);” from your Update() when you want the sound to play. (Since you have 2 audio files, I would think you’d want to play them back-to-back or something, which can be achieved with “audio.isPlaying()”).

On second thought, that may not work (I don’t have Unity in front of me right now), since the “audio” member variable/property is read-only. If indeed it doesn’t work, try this:

var audio1 : AudioClip;
var audio2 : AudioClip; 
var audioSource : AudioSource;

function YourSoundPlayingFunction() {
   /// ... possible conditional code ...
   audioSource.Play(audio1);
   /// ... possible conditional code ...
}

Then just set the “audioSource” property to point to the AudioSource behavior of your choice.

Best of luck!

Nah. It’s easier to use the one-shot technique for most sounds like explosions.

AudioSource.PlayClipAtPoint(clipName, position, volume) is the easiest way to handle that.

AudioSource.PlayClipAtPoint(audio1, 1, 1); doesnt work.

No appropriate version of unityengine.audiosource.playclipatpoint for the argument…