Different sounds (C#)

Hello

I hope you guys can help me with a sound problem of mine.

I have a Spotlight on which I have a script attached, and two Audio sources ( two different sounds).

In the script there I have written two similiar If statements.
Part of the code below.

if ( fval == 1000){
	count = true;
	}
	if (count){
	if (x == 10 ){
audio.Play();
			}

(And the other sounds should play when the fval has another value in its own If statement.)

It plays the first added sound just fine with audio.Play();

But How do I declare the other sounds in the If statement that follows.
The sound that plays fine first is for example named “crash” and the other I want to be played is named “hit”

Ive tried to look at the API but I cant figure it out. Ive tried declaring the sounds with something like "var crash: AudioClip; But that didnt really do it.
How do I declare the other sounds and tell the audio,Play which sound to play ?

Scripting really isnt my field.
I hope Iam making myself clear.

Thanks in advance :smile:

try this. attach 2 gameobjects to it, each with it’s own sound, then you can do transform.Find(“objectwithsound1”).audio.Play() and transform.Find(“objectwithsound2”).audio.Play().

You could then just predefine them in the script and say Audio1.Play() and Audio2.Play… if you were less lazy then I.

Hello, I’m not sure I understand the real issue, but if you want to switch between sounds then, instead of using two AudioSources, use one and in the code you declare the clips in the beginning, outside the functions:

crash: AudioClip;
hit: AudioClip;
jump: AudioClip;

… and so on. (In the editor, just link them to the sounds by drag&drop the sounds on them)

Then you need to either use:

 audio.clip = hit;
audio.Play();

or:

audio.PlayOneShot(hit);

EDIT: or you could use BigMisterB’s solution if you’ll play the sounds simultaneously.
I hope that helped
/Kweiko