- Home /
How do I stop sound from looping on button press again
I have a simple button script for a two state button, but I'm having trouble trying to figure out how to make the sound stop looping when I press the button again. Here is what my script looks like.
//var levelToLoad : String;
var mouseUpTexture : Texture2D;
var mouseDownTexture : Texture2D;
var beep : AudioClip;
var SurveillanceSoundFX : AudioClip;
function OnMouseDown(){
guiTexture.texture = mouseDownTexture;
audio.PlayOneShot(beep);
audio.loop = true; audio.clip = SurveillanceSoundFX; audio.Play();
}
function OnMouseUp(){
guiTexture.texture = mouseUpTexture;
yield new WaitForSeconds(0.3);
//Do Something
}
You should set this question as closed if you solved it.
Click on close (you find it under your question)
I'm sorry. To be able to close your own questions you must have at least 50 karma, and I thought you have enough karma to do it.
Answer by KnightRiderGuy · Dec 06, 2014 at 11:00 PM
Never mind.... figured it out, I just needed to add this to my mouseDown function:
if (audio.isPlaying)
{
audio.Pause ();
}
else
{
audio.Play ();
}
Your answer
Follow this Question
Related Questions
Loop animation 1 Answer
Looping an AudioClip var... 1 Answer
how to insert hover effect on unity button and active color button when the button is being click ? 0 Answers
Highlighted buttons stay highlighted when I deactivate a canvas. No way to unhighlight them. 1 Answer
Audio source play stop in Unity5 3 Answers