Hi everybody, I wonder if it's possible to use a gameObject like a button for an audio.clip . Explanation : I would like to play a sound when I walk through an empty game object for the first time. I walk through it for the second time, stop the sound. Just like a button. I try,naturely : Code (csharp): var son : AudioClip; function OnTriggerEnter () { audio.clip = son; audio.Play(); } But after,I've got no Idea for the "stop()" process... Thank you for your attention Gul
Just a guess but maybe you can make a variabele (boolean) which tells you if the sound is playing... Code (csharp): var son : AudioClip; var playing : boolean = false; function OnTriggerEnter () { audio.clip = son; if(!playing) { audio.Play(); playing = true; } if(playing) { audio.Stop(); playing = false; } }
Thanks for your fast reply ! But I try your code, the "playing" var checked and not checked, this is the same : the sound is "off" Why ?
Have you attached a AudioSource to the GameObject? In that case you can just check the isPlaying flag Code (csharp): var son : AudioClip; function OnTriggerEnter () { audio.clip = son; if(!audio.isPlaying) audio.Play(); else audio.Stop(); }
Doleman, you've got the powa ! ^^ It's okay, an audioSource was assigned to a gameObject, Just only the syntax was wrong ! Thank you very much Gul