It looks as though it should work. Are you getting any error messages? If not, try putting a print statement in the Stop method, just to make sure it is getting called when you think it is.
I’m not sure how JS works, but if this was written in C#, i believe the script would stop running. It wouldn’t work because there is no “action” function, and therefore there is no coroutine to start.
This is closer to the correct code. I don’t know much JS, but I think this should work.
var action = "Demo";
function OnMouseDown () {
StartCoroutine(action);
}
function OnMouseUp() { Stop(); }
function Demo () {
audio.Play();
}
function Stop () {
StopCoroutine("Demo");
}
Well I should reformulate the question: In the current code, StopCoroutine is pointless because there will be no coroutine to stop. Demo enters, starts the sounds and immediately leaves again. Thats why I asked for the real code.
Am I right to assume that you missbelieve that stopping the Demo coroutine, even if it would still be running, would anyway impact the sound?
If so then you are wrong
The right thing to do would be stopping the audio again in Stop