- Home /
How to stop Audio not all??
Hi guys i would like to ask something, just picture this in your head say you have 3 GUIs on the screen each plays a song. when you click on GUI one the song will start and etc. what i want is if i click on the 3rd GUI button which will say Track 3 i want the first music to stop playing only, i want the 2nd GUI and the 3rd GUI song to keep on playing. I have tried:
audio.Stop();
Now if i use that it stops all the sounds and plays the one you clicked on, Now is there anyway that i can stop a specific soundtrack only in this case the first one.
i have tried
audio.Stop(Name of the Var in here);
and that brings up a error on in unity
can someone please help me put an end to this problem thanks in advance
:)
here is the script :
var MyAudioTrack1Naruto : AudioClip; var MyAudioTrack2Naruto : AudioClip; var MyAudioTrack3Naruto : AudioClip; var MyAudioTrack4Naruto : AudioClip; var MyAudioTrack5Naruto : AudioClip;
function OnGUI () {
//Make the first button
if(GUI.Button (Rect(10, 20,105,20), "Play Track 1 (Naruto Enter) ")){
if (!audio.isPlaying){
//audio.Stop(); //if something else is playing stop it and then play track
audio.clip = MyAudioTrack1Naruto;
audio.PlayOneShot(MyAudioTrack1Naruto);
}
}
if (GUI.Button (Rect(10, 42,105,20), "Play Track 1 (Naruto Enter) ")){
audio.PlayOneShot(MyAudioTrack2Naruto);
}
if (GUI.Button (Rect(10, 64,105,20), "Play Track 1 (Naruto Enter) ")){
audio.PlayOneShot(MyAudioTrack3Naruto);
}
if (GUI.Button (Rect(10, 86,105,20), "Play Track 1 (Naruto Enter) ")){
audio.PlayOneShot(MyAudioTrack4Naruto);
}
if (GUI.Button (Rect(10, 108,105,20), "Play Track 1 (Naruto Enter) ")){
audio.PlayOneShot(MyAudioTrack5Naruto);
}
if (GUI.Button(Rect(10, 128,105,20), " No track ")){
}
}
How many audiosources do you use? How do you play them? where is/are the audio source(s) attached? What so you mean by GUI? A GUITexture? or a True GUI created in OnGUI()? Your question is a bit confusing... So you want to play max. two songs at once and when clicking on another the olderst song stops and the new one starts?
No what i want to do is if i click on the GUIs i want them to play songs, i know they will over lap but what i am trying to say is if the user hits the track 3 GUI i want the 2nd track to keep playing but the first track will stop. So that means i know have track 2 and 3 playing :)
Your answer
Follow this Question
Related Questions
Which sound files does unity support for games? 1 Answer
Sound stops when object is destroyed 6 Answers
A node in a childnode? 1 Answer
Unity disables my Sound Card 1 Answer