rooted
1
I have an audio clip of a gunshot that is pitched down so that I can get it in Unity just over the minimum length allowed. I then pitch it up and loop it for a machine gun sound. I can’t get it to stop and start smoothly without it cutting into the loop causing a distorted clipping sound at least 50% of the time. Is this a limitation of Unity? I need some parameter that starts and stops the clip accurately every time to not get the clipping sound.
Here is my code so far:
function Update () {
if(Input.GetMouseButtonDown(0)) {
gunLoop.Play ();
}
if(Input.GetMouseButtonUp(0)) {
WaitForSeconds (gunLoop.clip.length);// this doesn't seem to matter
gunLoop.Stop ();
audio.PlayOneShot(gunStop,1);
}
}
Use the loop property:
function Update () {
if(Input.GetMouseButtonDown(0)){
gunLoop.loop = true; // turn looping on
gunLoop.Play (); // and start sound
}
if(Input.GetMouseButtonUp(0)) {
gunLoop.loop = false; // turn looping off to stop sound
}
}