- Home /
Sound Stop playing on button release
Once again hello beautiful Unity Answers members! I have been biting my lip over this for an hour now. In my short demo level, I want a fireball to appear when the player holds down the right mouse key, and disappear when he releases this key. I got the particle system to work, but no matter how i edit this script for the sound, I cant get it to work! I need the sound to loop if the right mouse key is held down, and to stop playing when the right mouse key is released. Script:
var firesound : AudioClip;
function Start () {
particleEmitter.emit = false; }
function Update ()
{
if (Input.GetMouseButtonDown (1)){
particleEmitter.emit = true;
audio.PlayOneShot(firesound);
if (Input.GetMouseButtonUp (1))
particleEmitter.emit = false;
audio.stop(firesound); } }
Halp?
Answer by fafase · Sep 23, 2012 at 03:04 PM
Stop is a function, it starts with a cap S.
function Update (){
if (Input.GetMouseButtonDown (1)){
particleEmitter.emit = true;
audio.Play();
if (Input.GetMouseButtonUp (1))
particleEmitter.emit = false;
audio.Stop();
}
}
Answer by alpaca of zion · Sep 23, 2012 at 02:42 PM
Use auidio.play instead of Play One Shot.
http://answers.unity3d.com/questions/123772/playoneshot-returns-false-for-isplaying.html
Your answer