I am currently working on a 2d game and have hit a snag with my audio. I am able to get the audio to play when I press my movement buttons but the audio is being called every frame. Because of this I get an annoying buzzing sound while my audio is being played. I need to figure out how to stop the audio from playing every frame. I have tried using audio.PlayOneShot(audioClipVariable). This gets rid of the buzzing sound but plays the audio back too fast. I’m thinking PlayOneShot will fix the problem but I then need to know how to slow down the playback rate.
Playback speed is directly related to the original sound file and the audio source’s pitch. In this instance, I’d say set up a static audio source on the character or on the camera that listens for it, set it to automatically loop, change the pitch until it’s where you want it, and then audio.Pause() when no movement keys are down (once) and audio.Play() when movement keys start up again.
You can usually set a boolean for that. If not moving and boolean == true, boolean = false;, audio.Pause();. If moving and boolean == false, boolean = true;, audio.Play();. Should work just fine!