- Home /
Question by
thommoboy · Apr 15, 2012 at 12:54 PM ·
androidjavascript
Audio Clumping
hey once again,
Whenever I shoot pressing my on-screen button it plays the audio, but multiple times within a few seconds here is my code:
any help?
Comment
Please just post the relevant code, not a link to your whole script!
Your Play() instruction must be called by mistake more than once. Is your button a repeat button? Is your Play() instruction inside a for loop ar the Update function?
Answer by Lttldude · Apr 15, 2012 at 06:22 PM
I think this section of code is running a few times, when you want it to run only once. Add a simple Print("Shooting.") line of code so you know how many times this conditional statement runs.
A possible solution is putting a small wait time between firing, like 1 second.
var shootWaitTime : float = 1.0;
if (shootTouchPad.tapCount >= 1 && Time.time >= nextShootTime)
{
nextShootTime = Time.time + shootWaitTime;
RayShoot();
PlayShootAudio();
Print("Shooting."); //this is just to see how many times this conditional statement runs
}
Please tell me if this doesn't work.
Good Luck.
Your answer
![](https://koobas.hobune.stream/wayback/20220613070344im_/https://answers.unity.com/themes/thub/images/avi.jpg)