Check if a hitsound is already playing...

Hi

I want to check if a hitsound is already playing.
It’s a ball that can bounce several time on the same
object…

I tried audio.isPlaying…

var hitClip : AudioClip;

function OnCollisionEnter(collision:Collision){
    	audio.clip = hitClip;
    	
    	if (!audio.isPlaying){
    	audio.PlayOneShot(hitClip);	
    		
    	}
}

… but it doesn’t work…
It’s probably real simple, but I can’t figure it out!

Please help!

/errormaker (making fewer and fewer errors btw…)

Please post more info on the result you’re seeing: “it doesn’t work” leaves us little to go on…

OK…

Every time the ball bounce (rapidly…) it generate the hitsound
even if the previous sound still playing.
The hitsound can be up to 2 seconds…
The result: a soundmess…

audio.isPlaying is only for audio.clip and audio.Play(). PlayOneShot is something different that supposedly allows you to have multiple clips for one audio source, but I suspect it’s really doing something like PlayClipAtPoint behind the scenes.

–Eric

Ahh yes, I overlooked that Eric. Sounds like it could be doing something similar (to PlayClipAtPoint).

Easy test for errormaker; use Play() instead and see if the problem goes away.

It worked!
Thank You all!

errormaker

Hey Errormaker, your nickname defines me well :slight_smile: I am having troubles with the ball sound too. I have a physix ball bouncing inside a board and I want to add the bouncing sounds, but it seems incredibly difficult to adjust the bouncing sound by the OnCollisionEnter function. My board has a slope and when the ball roles down it it sounds the bouncing sound. I tryied to fix this using collision.impactForceSum and collision.relativeVelocity with no luck. Maybe the issue comes because I have a gravity of (0, -600, -50)… What do you think?

EDIT: I solved this issue playing the sound only with walls :slight_smile: